Question: java program 2 Rational Implement a class to represent rational numbers. Each rational number consists of a numerator and a denominator, both of type int.
java program


2 Rational Implement a class to represent rational numbers. Each rational number consists of a numerator and a denominator, both of type int. Since each rational number has its own numerator and denominator, these must be instance variables. Furthermore, good object-oriented programming suggests that the visibility of the variables should be private. 3 Constructors The class Rational has two constructors. One of them has two formal parameters, which provide the initial values for both instance variables. The other constructor has a single parameter, which provides the initial value for the numerator: the denominator is assumed to be 1 4 getters Implement access methods that return the numerator and denominator of this rational, but no setter methods. An object that has no setter methods, and no other methods for 2 Rational Implement a class to represent rational numbers. Each rational number consists of a numerator and a denominator, both of type int. Since each rational number has its own numerator and denominator, these must be instance variables. Furthermore, good object-oriented programming suggests that the visibility of the variables should be private. 3 Constructors The class Rational has two constructors. One of them has two formal parameters, which provide the initial values for both instance variables. The other constructor has a single parameter, which provides the initial value for the numerator: the denominator is assumed to be 1 4 getters Implement access methods that return the numerator and denominator of this rational, but no setter methods. An object that has no setter methods, and no other methods for
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
