Question: JAVA: Suppose we want to implement a rational number class called Rational. Each object of Rational represents a rational number with an integer numerator and
JAVA:
Suppose we want to implement a rational number class called Rational.
Each object of Rational represents a rational number with an integer numerator and a nonzero integer denominator.
The instance variables of Rational corresponding to the numerator and denominator are int n and int d.
Implement the following instance method of Rational:
public Rational add(Rational other)
The result should be a new Rational object constructed by adding this to other.
The Rational constructor takes two parameters to initialize n and d respectively.
The constructor will reduce numerator and denominator to lowest terms. Your add method doesn't need to do that.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
