Problem

Write a Java class Fraction that implements the interface you designed in the previous p...

Write a Java class Fraction that implements the interface you designed in the previous project. Begin with reasonable constructors. Design and implement useful private methods, and include comments that specify them.

To reduce a fraction such as 4/8 to lowest terms, you need to divide both the numerator and the denominator by their greatest common denominator. The greatest common denominator of 4 and 8 is 4, so when you divide the numerator and denominator of 4/8 by 4, you get the fraction 1/2. The following recursive algorithm finds the greatest common denominator of two positive integers:

Algorithm gcd(integerOne, integerTwo)

if (integerOne % integerTwo == 0)

result = integerTwo

else

result = gcd(integerTwo, integerOne % integerTwo)

return result

It will be easier to determine the correct sign of a fraction if you force the fraction’s denominator to be positive. However, your implementation must handle negative denominators that the client might provide. Write a program that adequately demonstrates your class.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter P
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT