Hi, I'm having trouble programming this fraction program. Right now my homework says that I have to program an division class that has two parameters, and it returns the quotient of two fractions. The other one is an addition one that returns the sum of two fractions, using two parameters

Everything in the program works except the parts i tried adding. I put the errors that I get in jcreator next to them, so hopefully some one can help.

Quote:

// James Novak

// Fraction.java

// September 8, 2009

import java.util.Scanner;

/** new fraction data type, and that the faction may only be positive or zero,

*the fraction will always be in lowest terms

*

*/

public class Fraction

{

private int top; //numerator

private int bottom; //denominator

public Fraction()

{

top = 0;

bottom = 1;

}

/** The fraction () method is a default constructor that creates

* a default fraction that is equal to zero.

*

*/

public Fraction(int num, int denom)

{

if (denom == 0)

throw new IllegalArgumentException("Second argument " + denom + " cannot be zero.");

if (num < 0 || denom < 0)

throw new IllegalArgumentException("Both arguments, " + num + " and " + denom + ", cannot be negative.");

top = num;

bottom = denom;

reduce();

}

/** the method assign gives new values to the numerator and denominator

* of an existing Fraction

* @param num The value to assign to the numerator

* @param denom The value to assign to the denominator

* @exception IllegalArgumentException When the second argument is zero

* @exception IllegalArgumentException When either argument is negative

*/

public void assign(int num, int denom)

{

if (denom == 0)

throw new IllegalArgumentException("Second argument " + denom + " cannot be zero.");

if (num < 0 || denom < 0)

throw new IllegalArgumentException("Both arguments, " + num + " and " + denom + ", cannot be negative.");

top=num;

bottom=denom;

reduce();

}

/** The static multiply method returns the product

*of the two parameters

*@param f1 the first fraction to multiply

*@param f2 the second fraction to multiply

*@return The product of the f1 and f2

*/

public static Fraction multiply(Fraction f1, Fraction f2)

{

Fraction temp = new Fraction();

temp.top = f1.top * f2.top;

temp.bottom = f2.bottom * f2.bottom;

temp.reduce();

return temp;

}

private void reduce()

{

if (top == 0)

bottom = 1;

else

{

int min = (top < bottom ? top : bottom);

int gcd; //greatest common divisor

for (gcd = min; gcd > 1; --gcd)

if (top % gcd == 0 && bottom % gcd == 0)

break;

top = top / gcd;

bottom = bottom / gcd;

}

}

public void output()

{

if (top == 0)

{

System.out.print(0);

return;

}

if (top >= bottom)

{

System.out.print(top / bottom);

if (top % bottom != 0)

System.out.print(" and ");

}

if (top % bottom != 0)

System.out.print(top % bottom + "/" + bottom);

}

public void input()

{

Scanner keyboard = new Scanner(System.in);

String line = keyboard.nextLine();

int slash;

int total = line.length();

slash = -1;

for (int i = 0; i < total; ++i)

{

if (line.charAt(i) == '/')

{

slash = i;

break;

}

}

if (slash == -1)

{

System.out.println("ERROR in input");

}

else

{

String first = line.substring(0, slash);

String second = line.substring(slash + 1, total);

first = first.trim();

second = second.trim();

top = Integer.parseInt(first);

bottom = Integer.parseInt(second);

reduce();

}

}

public boolean equals(Fraction f2)

{

if (top == f2.top && bottom == f2.bottom)

return true;

else

return false;

}

public boolean lessThan(Fraction f2)

{

double temp1 = (double)top / bottom;

double temp2 = (double)f2.top / f2.bottom;

if (temp1 < temp2)

return true;

else

return false;

}

public boolean greaterThan(Fraction f2)

{

double temp1 = (double)top / bottom;

double temp2 = (double)f2.top / f2.bottom;

if (temp1 > temp2)

return true;

else

return false;

}

public static void divide(Fraction f2); //Error: Missing method body, or declare abstract

{

double quotientA = (double)top / bottom; //ERROR: cannot find symbol variable f2

double quotientB = (double)f2.top / f2.bottom; //ERROR: cannot find symbol variable f2

}

public static void addition(Fraction f2);

{

double newTop = (double)f2.bottom * top + f1.bottom * f2.top; //error cannot find symbol viarable f2

double newBottom = (double)bottom * f2.bottom; //error cannot find symbol variable f2

}

}