Write a class called Fraction.java; this class will be designed to handle fractions. The Fraction class has only two instance variables: - An integer numerator - An integer denominator The two instance variables can be publicly accessible (at this stage). Supply an input method for the Fraction class; this method will be used by the client to get a fraction (as two separate integer inputs) from the user. The input method should ensure that the denominator cannot be 0. Supply an output method for the Fraction class; this method will be used by the client to print out a fraction (as two separate integers) to the screen. An output fraction would be in the form: numerator / denominator An example: the fraction for a half would be input as 1 for the first input and 2 for the second input. The output should be printed out as 1 / 2. Once this is done, write a client class program called TestFraction.java; this class is to be used to test your Fraction class. The program should loop around getting fractions from the user and displaying them to the screen. Stop when the numerator is negative. Note that the client program should use the Fraction class methods (via the dot notation) to read and display fractions.
Write a class called Fraction.java; this class will be designed to handle
fractions. The Fraction class has only two instance variables:
- An integer numerator
- An integer denominator
The two instance variables can be publicly accessible (at this stage). Supply an
input method for the Fraction class; this method will be used by the client to
get a fraction (as two separate integer inputs) from the user. The input method
should ensure that the denominator cannot be 0. Supply an output method for
the Fraction class; this method will be used by the client to print out a fraction
(as two separate integers) to the screen.
An output fraction would be in the form:
numerator / denominator
An example: the fraction for a half would be input as 1 for the first input and 2
for the second input. The output should be printed out as 1 / 2.
Once this is done, write a client class
class is to be used to test your Fraction class. The program should loop around
getting fractions from the user and displaying them to the screen. Stop when
the numerator is negative.
Note that the client program should use the Fraction class methods (via the dot
notation) to read and display fractions.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images