Question: Create a class Rational that represents a rational number. It should have private attributes for The numerator (an integer) The denominator (an integer) and the
Create a class Rational that represents a rational number. It should have private attributes for
- The numerator (an integer)
- The denominator (an integer) and the following methods:
- Rational(numerator, denominator)—a constructor for a rational number.
- Accessor methods getNumerator and getDenominator and mutator methods setNumerator and setDenominator for the numerator and the denominator.
You should use an exception to guarantee that the denominator is never zero.
Step by Step Solution
3.55 Rating (165 Votes )
There are 3 Steps involved in it
public class Rational private int numerator private int denominator Creates a new instance of Rational public Rationalint theNumerator int theDenomina... View full answer
Get step-by-step solutions from verified subject matter experts
