[Solved]Please Solve Java Write Fraction Class Whose Objects Represent Fractions Provide Following Q37138607
Please solve in java
Write a Fraction class whose objects will represent fractions.You should provide the following class methods:
-
Two constructors, a parameter-less constructor that assigns thevalue 0 to the Fraction, and a constructor that takes twoparameters. The first parameter will represent the initialnumerator of the Fraction, and the second parameter will representthe initial denominator of the Fraction.
-
Arithmetic operations that add, subtract, multiply, and divideFractions. These should be implemented as value returning methodsthat return a Fraction object. They should be named addedTo,subtract, multipliedBy, and dividedBy.
-
A boolean operation named isEqualTo that compares two Fractionobjects for equality.
-
An output operation named print that displays the value of aFraction object on the screen in the formnumerator/denominator.
Your class should have exactly two private data members, one torepresent the numerator of the fraction being represented, and oneto represent the denominator of the fraction being represented.
When adding or subtracting Fractions, remember that you mustfirst find the common denominator. The easy way to do this is tomultiply the denominators together and use that product as thecommon denominator.
I am providing a client program for you below. You should copyand paste this into a file and use it as your client program. Theoutput that should be produced when the provided client program isrun with your class is also given below, so that you can check yourresults. Since you are not writing the client program, you are notrequired to include comments in it.
I strongly suggest that you design your class incrementally. Forexample, you should first implement only the constructors and theoutput method, and then test what you have so far. Once this codehas been thoroughly debugged, you should add additional classmethods, testing each one thoroughly as it is added. You might dothis by creating your own client program to test the code at eachstage; however, it would probably be better to use the providedclient program and comment out code that relates to class methodsthat you have not yet implemented.
As you can see from the sample output given below, you are notrequired to change improper fractions into mixed numbers forprinting. Just print it as an improper fraction. You are, however,required to reduce fractions, as illustrated in the sample output.Make sure that your class will reduce ANY fraction, not just thefractions that are tested in the provided client program. Fractionsshould not be simply reduced upon output, they should be stored inreduced form at all times. In other words, you should ensure thatall fraction objects are reduced before the end of any classmethod. You are also not required to deal with negative numbers,either in the numerator or the denominator.
You must create your own algorithm for reducing fractions. Don’tlook up an already existing algorithm for reducing fractions orfinding GCF. The point here is to have you practice solving theproblem on your own. In particular, don’t use Euclid’s algorithm.Don’t worry too much about efficiency, just create something ofyour own that works correctly on ANY fraction.
Here is the client program. It must be in a separate file fromyour class.
![public class ChangeThi sClassName public static void main(String] args) Fraction few Fraction 9, 8) Fraction f2 new Fraction](https://media.cheggcdn.com/media%2Fff3%2Fff3ca586-8bf6-48ce-93b9-86f1bf572c44%2Fphpf1d8EP.png)
This client should produce the output shown here:
The result starts off at 0/1The product of 9/8 and 2/3 is 3/4The quotient of 9/8 and 2/3 is 27/16The sum of 9/8 and 2/3 is 43/24The difference of 9/8 and 2/3 is 11/24The two fractions are not equal.The product of 3/2 and 2/3 is 1/1
You may not change the client program in any way, exceptthat you may change the name of the main class. Changing the clientprogram in any other way will result in a grade of 0 on theassignment.
You do not need to submit your client file. Execute your programand copy/paste the output into the bottom of your Fraction.javafile, making it into a comment. Use the Assignment Submission linkto submit the file. When you submit your assignment there will be atext field in which you can add a note to me (called a “comment”,but don’t confuse it with a Java comment). In this “comments”section of the submission page let me know whether the programworks as required.
public class ChangeThi sClassName public static void main(String] args) Fraction few Fraction 9, 8) Fraction f2 new Fraction (2, 3) Fraction resultnew Fraction Sys tem. out. print( The result starts off at “); result. print): Sys tem. out. printlnf.O Sys tem. out. print( The product of “): fl. print: Sys tem. out. print( and SPrnt result fl. multipliedBy(f2) result. print) Sys tem. out. println Sys tem. out. printí” is Sys tem. out. print( The qotient of): f1. print Sys tem. out. print and”); f2. print) System, out, print” is”) result £1. divi dedBy(f2): result print): Sys tem. out. printlnf.O Sys tem. out printl The sum of “); fl. print: Sys tem. out. print( and System, out, print (1s result f1. addedTo £2) result.print): Sys tem. out. println Sys tem. out. print( The difference of “) prınt Sys tem. out. print and”); f2. print) System. out. print” is result £1. subtract f2 result print): Sys tem. out. printlnf.O if (fl isEqualTo (£2))I System. out. printlnl The two Fractions are equal. “): System. out. println( The two Fractions are not equal.”): Fraction 3new Fraction (12, 8) Fraction f4 new Fraction (202, 303) result f3. multipliedBy(f4) Sys tem. out. print( The product of “); f3. print): Sys tem. out. print and”); f4. print() System. out. print! result. print); Sys tem. out. println This client should produce the output shown here: The result starts off at 0/1 The product of 9/8 and 2/3 is 3/4 The quotient of 9/8 and 2/3 is 27/16 The sum of 9/8 and 2/3 is 43/24 The difference of 9/8 and 2/3 is 11/24 The two fractions are not equal The product of 3/2 and 2/3 is 1/1 Show transcribed image text public class ChangeThi sClassName public static void main(String] args) Fraction few Fraction 9, 8) Fraction f2 new Fraction (2, 3) Fraction resultnew Fraction Sys tem. out. print( The result starts off at “); result. print): Sys tem. out. printlnf.O Sys tem. out. print( The product of “): fl. print: Sys tem. out. print( and SPrnt result fl. multipliedBy(f2) result. print) Sys tem. out. println Sys tem. out. printí” is Sys tem. out. print( The qotient of): f1. print Sys tem. out. print and”); f2. print) System, out, print” is”) result £1. divi dedBy(f2): result print): Sys tem. out. printlnf.O Sys tem. out printl The sum of “); fl. print: Sys tem. out. print( and System, out, print (1s result f1. addedTo £2) result.print): Sys tem. out. println Sys tem. out. print( The difference of “) prınt Sys tem. out. print and”); f2. print) System. out. print” is result £1. subtract f2 result print): Sys tem. out. printlnf.O if (fl isEqualTo (£2))I System. out. printlnl The two Fractions are equal. “): System. out. println( The two Fractions are not equal.”): Fraction 3new Fraction (12, 8) Fraction f4 new Fraction (202, 303) result f3. multipliedBy(f4) Sys tem. out. print( The product of “); f3. print): Sys tem. out. print and”); f4. print() System. out. print! result. print); Sys tem. out. println This client should produce the output shown here: The result starts off at 0/1 The product of 9/8 and 2/3 is 3/4 The quotient of 9/8 and 2/3 is 27/16 The sum of 9/8 and 2/3 is 43/24 The difference of 9/8 and 2/3 is 11/24 The two fractions are not equal The product of 3/2 and 2/3 is 1/1
Expert Answer
Answer to Please solve in java Write a Fraction class whose objects will represent fractions. You should provide the following cla… . . .
OR

