Question: Design, implement and test a Rational class that represents a rational number as a pair of integers instead of a single floating double number. The

Design, implement and test a Rational class that represents a rational number as a pair of integers instead of a single floating double number. The Rational class should have two class constructors. The first one lets the client specify an initial numerator and denominator. The other the default constructor creates the rational number 0, represented as a numerator of 0 and denominator of 1. The sequence of client code

Rational num1(1,3);

Rational num2(3,1);

System.out.print(The product of +num1+ and +num2+ is );

System.out.println(num1.MultipliedBy(num2));

would produce the output

The product of 1/3 and 3/1 is 1/1.

At the very least, you should provide the following class member functions:

Constructors for explicit as well as default initialization of Rational objects

Arithmetic operations that add, subtract, multiply and divide two Rational objects. These should be implemented as value-returning functions, each returning a Rational object.

A Boolean operation that compares two Rational objects for equality.

A toString method that displays the value of a Rational object in the form numerator/denominator

A method to simplify fractions to lowest terms

A method to find the reciprocal of a Rational object

Bonus: Expand the class to correctly process mixed numbers. Additions would include a constructor for mixed numbers and methods to convert mixed numbers to improper fractions and vice versa.

This program must be done in java.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!