Hints: Two rational numbers a/b and c/d are equal if a*d equals c*b.

You should define the following methods:

public Rational(int numerator, int denominator)

public Rational(int wholeNumber)

public Rational()

public void normalize()

public void setNumerator(int numerator)

public int getNumerator()

public void setDenominator(int denominator)

public int getDenominator()

public boolean equals(Rational obj)

public static Rational add(Rational r1, Rational r2)

public static Rational subtract(Rational r1, Rational r2)

public static Rational multiply(Rational r1, Rational r2)

public static Rational divide(Rational r1, Rational r2)

To aid in testing, you may also wich to implement a method that will return the value of the Rational as a double:

public double getDoubleValue()

/** Class representing rational numbers */ class Rational { /** The number's numerator */ private int numerator; /** The number's denominator */ private int denominator; /** Returns a String representing the number */ public String toString() { return numerator + "/" + denominator; } } /** Test class that exercises the methods of Rational */ public class RationalDemo { public static void main(String[] args) { // Test constructor, setters, toString, and normalize Rational oneHalf = new Rational(); oneHalf.setNumerator(1); oneHalf.setDenominator(2); System.out.println("One half: " + oneHalf); Rational twoQuarters = new Rational(); twoQuarters.setNumerator(-2); twoQuarters.setDenominator(-4); System.out.println("Before normalization: " + twoQuarters); twoQuarters.normalize(); System.out.println("After normalization: " + twoQuarters); Rational negativeThree = new Rational(-3); System.out.println("Negative three: " + negativeThree); Rational twoThirds = new Rational(2, 3); System.out.println("Two thirds: " + twoThirds); // Test the getter methods System.out.println( "Numerator of " + twoThirds + ": " + twoThirds.getNumerator()); System.out.println( "Denominator of " + twoThirds + ": " + twoThirds.getDenominator()); System.out.println( "Value of " + twoThirds + ": " + twoThirds.getDoubleValue()); // Test equality System.out.println( oneHalf + " = " + twoThirds + " ? " + oneHalf.equals(twoThirds)); System.out.println( oneHalf +" = " + twoQuarters + " ? " + oneHalf.equals(twoQuarters)); // Test the arithmetic operations System.out.println(oneHalf + " + " + twoThirds + " = " + Rational.add(oneHalf, twoThirds)); System.out.println(oneHalf + " - " + twoThirds + " = " + Rational.subtract(oneHalf, twoThirds)); System.out.println(oneHalf + " * " + twoThirds + " = " + Rational.multiply(oneHalf, twoThirds)); System.out.println(oneHalf + " / " + twoThirds + " = " + Rational.divide(oneHalf, twoThirds)); } }

Any Help Plz

Thanks Sooo much