Question: Create a java program named RationalNumber with the following specifications: Data fields: int numerator, int denominator Constructor: public RationalNumber(int n, int d) Instance methods: a)
Create a java program named RationalNumber with the following specifications:
Data fields: int numerator, int denominator
Constructor: public RationalNumber(int n, int d)
Instance methods:
a) public RationalNumber add(RationalNumber r) //Adds the rational number in the object containing the called method and the rational number in the r object. Returns a new RationalNumber object that contains the sum
b) public RationalNumber multiply(RationalNumber r) // Multiplies the rational number in the object containing the called method and the rational number in the r object. Returns a new RationalNumber object that contains the product
c) Public void reduce() //Reduces the rational number to lowest terms. Does not create a new object
d) Public String toString() //Returns a string representing the value of the rational number. The string returned should include the slash character between the numerator and the denominator.
e) Test with 3/7 and 7/3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
