Question: write the code in Java Complete the design and coding for a Fraction class. A Fraction is not a supported data type in Java, but

write the code in Java Complete the design and coding for awrite the code in Java

Complete the design and coding for a Fraction class. A Fraction is not a supported data type in Java, but it might be interestig to explore how a Fraction data type might work. Since a Fraction is represented by its integer numerator and non-zero integer denominator, Fractions have the advantage of enabling exact answers for all arithmetic operations, whereas double or float data types have the rounding inaccuracy. Please convert all fractions so if there is a negative sign, it is in the numerator only (i.e. -3/-4 is the same as 3/4,5/-3 is the same as -5/3). Create a Fraction class with necessary instance attributes and class constants, and the following methods: Non-Default Constructor - Fraction (int numerator, int denominator) - All arguments should be checked for validity and a default value (1) used if necessary. Accessors - returns values of the instance variables Mutators - assigns new values to the instance variables, including error checking on the arguments Fraction add(Fraction arg) - returns a new Fraction equal to "this" plus "arg" Fraction subt[Fraction arg) - returns a new Fraction equal to "this" minus "arg" Fraction mult[Fraction arg) - returns a new Fraction equal to "this" times "arg" Fraction div[Fraction arg) - returns a new Fraction equal to "this" divided by "arg" .toString method that returns a String using a format of "numerator/denominator" reducel) - reduces the Fraction to its lowest terms equals(Fraction that) - returns true if this Fraction is equal to that Fraction, else returns false. To break down required functionality into smaller pieces, you should consider the following private methods that are used by the above public methods: void fixNegative) - moves the negative sign to the numerator int gcd(int a, b) - returns the greatest common divisor of a and b

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!