I need help creating a Fraction class that would work with the main method below

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcdgr8
    New Member
    • Mar 2010
    • 1

    I need help creating a Fraction class that would work with the main method below

    public class RationalTester
    {
    //----------------------------------------------------
    // Creates some rational number objects and performs various
    // operations on them.
    //----------------------------------------------------
    public static final int ARRAY_SIZE = 5;
    public static void main(String[] args)
    {
    Fraction f1 = new Fraction(1,2);
    Fraction f2 = new Fraction (2, 3);
    Fraction f3, f4,f5, f6, f7;

    Fraction[] fractionArray[ARRAY_SIZE]; //create array
    System.out.prin tln("First rational number: " + f1);
    System.out.prin tln("Second rational number: " + f2);
    if(f1.equals(f2 ))
    System.out.prin tln("f1 and f2 are equal.");
    else
    System.out.prin tln("f1 and f2 are NOT equal.");

    f3 = f2.reciprocal() ;
    System.out.prin tln("The reciprocal of f2 is: " + f3);

    f4 = f1.add(f2);
    f5 = f1.subtract(f2) ;
    f6 = f1.multiply(f2) ;
    f7 = f1.divide(f2);

    System.out.prin tln("f1 + f2: " + f4);
    System.out.prin tln("f1 - f2: " + f5);
    System.out.prin tln("f1 * f2: " + f6);
    System.out.prin tln("f1 / f2: " + f7);

    // The next two methods must be written. They are static method
    // RationalTester class.

    readFractionArr ay(fractionArra y);
    f7 = getAverage(frac tionArray);
    System.out.prin tln("The average of the array of s: " + f7);

    }
    public static void readFractionArr y(Fraction[] fracA)
    {

    }
    public static Fraction getAverage(Frac tion[] fracA)
Working...