Fractions class
I have the following assignment:
Design the class Fraction that can be used to manipulate fractions in a program. Among others, the class Fraction must include methods to add, subtract, multiply, and divide fractions. When you add, subtract, multiply, or divide fractions, your answer need not be in the lowest terms.
Write a Java console program using the class Fraction that performs operations on fractions. Override the method toString so that the fraction can be output using the output statement.
This is what I have so far:
import java.util.*;
publicclass Fraction
{
privatefinalint numerator;
privatefinalint denominator;
public Fraction(int num,int denom)
{
this.numerator = num;
this.denominator = denom;
}
publicint getNumerator()
{
return numerator;
}
publicint getDenominator()
{
return denominator;
}
public Fraction reciprocal()
{
int n;
int d;
n = getDenominator();
d = getNumerator();
returnnew Fraction(n, d);
}
public Fraction add(Fraction other)
{
//...
}
public Fraction subtract(Fraction other)
{
//...
}
public Fraction multiply( Fraction x )
{
returnnew Fraction ( numerator * x.numerator,
denominator * x.denominator);
}
public Fraction divide( Fraction x)
{
returnnew Fraction ( numerator * x.denominator,
denominator * x.numerator);
}
public String toString()
{
return numerator +"/" + denominator;
}
}
Can you guys see how I am screwing this up?
Thanks

