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.
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.