Question: Hi, I am taking a java class and I am stuck on this problem? Can anyone please help. Specify, design, and implement a class for

Hi, I am taking a java class and I am stuck on this problem? Can anyone please help.

Specify, design, and implement a class for rational numbers. Each object in the class should have two integer values that define the rational number: the numerator and denominator. for example the fraction 5/6 would have a numerator 5 and a denominator 6.

Include a constructor with two arguments that can be used to set the numerator and denominator (forbidding zero in the denominator). Also provide a no-argument construct that has zero for the numerator and 1 for the denominator.

Include a method that prints a rational number to System.out. Note that the numerator or denominator or both may contain a minus sign, but when a rational number is printed the denominator should never include a minus sign. So, if the numerator is 1 and the denominator is -2 then the printing method should print -1/2.

Write static methods for the usual arithmetic operations to provide addition, subtraction, multiplication, and the division of the two rational numbers.

There should also be a clone method to create clones of a rational number as well as an equals method to compare the equality of two rational numbers. Two rational numbers are equal is their numerators are equal and their denominators are equal.

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!