Page 1 of 1

Design a Fractions class – What attributes should it have? • Numerator, Denominator – What methods should it have? • Acc

Posted: Sun May 15, 2022 1:03 pm
by answerhappygod
Design a Fractions class
– What attributes should it have?
• Numerator, Denominator
– What methods should it have?
• Accessors and mutators
• reduce(), add(Fraction other), subtract(Fraction other)
• Reciprocal(), value()return as double, toString(),
toMixed()
• Create a class to test your Fractions class.
Fill the definition for the Fraction class members
and complete the program using the provided
skeleton.
After you have written the code add
comments to the code and also add things
to the testFraction class so that all the methods are
tested.
public class Fraction
{
//Attributes


//Constructor
public Fraction()
{
}

//Accessors

//Mutators


//Methods
public void reduce()
{
}

//add another fraction to this instance
public void add(Fraction other)
{
}

//subtracts another fraction from this instance
public void subtract(Fraction other)
{
}

public void reciprocal()
{
}

public double value()
{
}

public String toString()
{
}

public String toMixed()
{
}
}
public class TestFraction
{

public static void main(String[] args)
{
Fraction a = new Fraction(1,2);
Fraction b = new Fraction(4,6);
Fraction c = new Fraction(5,4);

System.out.println(a.toString());

System.out.println(b.toString());
b.reduce();
System.out.println(b.toString());

System.out.println(c.toMixed());

a.add(b);
System.out.println(a.toString());



}
}
This was the assignment^ up above
And below is what I have done so far but I need help to
initialize private fields and also complete multiply, divide,
equals, greaterThan, or lesserThan methods.