Create method simplify() to your Fraction class that converts a fraction to its simplest form. For example, the fraction 20 / 60 should be stored in the class instance variables as 1 / 3 (i.e. numerator = 1, denominator = 3). you will need a method to determine the Greatest Common Divisor (GCD. Remember, both of these methods (simplify and gcd) must be private. As these methods are private, client programs cannot access them. So, how are they to be used? They can only be accessed within the Fraction class. Given their purpose, it would mean that any Fraction class method that modifies the instance variables (e.g.: input, add, constructor, set) should call the simplify() method to reduce the instance variables to their minimum values. Thus, these methods are used only for housekeeping; they are not to be used by client programs.
Create method simplify() to your Fraction class that converts a fraction
to its simplest form. For example, the fraction 20 / 60 should be stored in the class instance variables as 1 / 3 (i.e. numerator = 1, denominator = 3).
you will need a method to determine the Greatest Common Divisor (GCD.
Remember, both of these methods (simplify and gcd) must be private. As
these methods are private, client
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images