Question: In Java Step 2: Write a class to hold data and methods for a Fraction. The integer fields will hold the values for the numerator
In Java
Step 2: Write a class to hold data and methods for a Fraction. The integer fields will hold the values for the numerator and denominator of a fraction. Each time you write a method, test that method in your driver class. Do not wait until you have written every method before testing. TEST AS YOU WRITE. In addition to the overloaded constructor methods write methods that will perform the following eight operations. When you create the Fraction do not accept zero as a value for the denominator. add two fractions, returning new Fraction reference that is the sum in lowest terms parameter: a reference to another Fraction return type: reference to a new Fraction subtract two fractions- returning a new Fraction reference that is difference in lowest terms (simplify) parameter: a reference to another Fraction return type: a reference to a new Fraction multiply two fractions-returning the product in lowest terms parameter: a reference to another Fraction, return type a reference to new Fraction that is the product of the two Fractions divide two fractions-returning the quotient in lowest terms parameter: a reference to another Fraction, return type: a reference to a new Fraction that is the quotient of the two Fractions compareTo( ) method parameter: a reference to a Fraction equals( ) method parameter: a reference to a Fraction a method to determine and return the decimal value of a fraction no parameters, return type: a double a static method to generate and return a reference to a random fraction that is between 0 and 1. (this means the numerator is less than the denominator) toString( ) method that returns a reference to a String in the form of a/b Here is a simple way to find the greatest common divisor of two numbers: Start with the smaller of the two numbers. Determine if this number goes into the larger of the two numbers evenly. If it does, this is the greatest common divisor, if not; repeatedly subtract 1 from the value of the smallest number until you find a value that goes into both numbers evenly. Step 3: Write a driver class with the main( ) method that tests each of the methods of the class. Be sure to print the output for each test case.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
