# Define a class called fraction, embed class in a test program.

Define a class called Fraction, used to represent a ratio of two integers.

1. Include mutator functions that allow the user to set the numerator and the denominator.

2. Also include a METHOD that displays the fraction on the screen as a ratio (e.g., 5/9). This method does not need to reduce the fraction to lowest terms.

3. Include an additional METHOD, "equals", that takes as input another Fraction and returns true if the two fractions are identical and false if they are not. This method should treat the fractions reduced to lowest terms; that is, if one fraction is 20/60 and the other is 1/3, then the method should return true.

4. Embed the class in a TEST PROGRAM that allows a user to create a fraction.

NOTES:

1. The objective is to compare before "dividing" to avoid any loss in resolution. Accordingly, just need to unify either the denominators or the numerators of both fractions. Do not have to "reduce" the fractions. Do "unification" WITHOUT using loops, for example:

a). n1/n2 and m1/m2 can be unified to: (n1*m2)/(n2*m2) and (m1*n2)/(m2*n2), then just compare the numerators.

b). Alternatively, unify the numerators as: (n1*m1)/(n2*m1) and (m1*n1)/(m2*n1), then just compare the denominators.

2. Embed class in a test program. Test the code with some hard-coded values. Use good descriptive comments throughout.

I have made several attempts at the solution, my logic is lame and so is my code. I have stripped down (see file). Need some assistance with unification part and completion to review and study working solution.

Thank you for your assistance,

J.R.

© BrainMass Inc. brainmass.com October 9, 2019, 10:47 pm ad1c9bdddfhttps://brainmass.com/computer-science/java/define-class-called-fraction-embed-class-test-program-232170

#### Solution Summary

The expert defines a class called fraction which is embed class in a test program.