Write a Java class Fraction that implements both the interface you designed in the previous project and the interface Comparable. Begin with reasonable constructors. Design and implement useful...


Write a Java class Fraction that implements both the interface you designed in the previous project and the interface Comparable. 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 its 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 algorithm finds the greatest common denominator of two positive integers:


Algorithm gcd(integerOne, integerTwo)


while (integerTwo != 0)


{


temp = integerOne % integerTwo


integerOne = integerTwo


integerTwo = temp


}


return integerOne


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.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here