Question: Main program File : FractionMath.java public class FractionMath { public static void main(String[] arguments) { // create four fractions accounts Fraction w = new Fraction();

![void main(String[] arguments) { // create four fractions accounts Fraction w =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3e8c1d1fce_86566f3e8c183d62.jpg)
Main program File : FractionMath.java
public class FractionMath { public static void main(String[] arguments) { // create four fractions accounts Fraction w = new Fraction(); Fraction x = new Fraction(3,4); Fraction y = new Fraction(2,5); Fraction z = new Fraction(6,0); System.out.println("*** Does the toStringMethod work?"); System.out.println("First fraction : " + w); System.out.println("Second fraction : " + x); System.out.println("Third fraction : " + y); System.out.println("Forth fraction : " + z); System.out.println(); // Does the get() method work? System.out.println("*** Does the get() methods work?"); System.out.println("w = " + w.getNumerator() + " over " + w.getDenominator()); System.out.println(); // Can we change the values correctly name System.out.println("*** Does the set() methods work?"); System.out.println("w fraction Before : " + w); w.setNumerator(22); System.out.println("w fraction After : " + w); w.setDenominator(55); System.out.println("w fraction After : " + w); w.setDenominator(0); System.out.println("w fraction After : " + w); System.out.println("The above line should be no different");
// Does the equality work System.out.println("Is " +w+ " eqaul to " +x+ "?"); System.out.println(" " + w.equals(x) ); System.out.println("Is " +w+ " eqaul to " +y+ "?"); System.out.println(" " + w.equals(y) ); System.out.println(); // Does the getDecimal work System.out.printf(x + " = %4.2f %n", x.getDecimalValue()); System.out.printf(y + " = %4.2f %n", y.getDecimalValue()); System.out.printf(z + " = %4.2f %n", z.getDecimalValue()); System.out.println(); // Does the multiply work System.out.println("x fraction Before : " + x); System.out.println("y fraction Before : " + y); x.multiply(y); System.out.println("x fraction After : " + x); System.out.println("y fraction After : " + y); System.out.println("*** Test #2 ***"); System.out.println("y fraction Before : " + y); System.out.println("z fraction Before : " + z); y.multiply(z); System.out.println("y fraction After : " + y); System.out.println("z fraction After : " + z); } }
Main program Fi FractionMathiava Very similar to assignment #19, for this assignment l want you to write a Fraction class that works with the FractionMath program above. You can download the above file, and then it should use your Fraction java file to run. Remember that fractions cannot have zero in the denominator, so if you ever have to change the denominator to zero, make it one instead. Your Craction class should have the following Fields o a numerator (int) o a denominator (int) Methods o A default constructor that sets the numerator to 1 that sets the denominator to 1 o A full constructor That accepts both the numerator and denominator. Note that if the denominator is zero, you should change it to a 1. o A toString0 method That returns a string in the format {space numerator denominator tspace 2/5 however, if the denominator is 1, then the fraction is a whole number so you should just return the numerator. i.e. do not print 4/1 just print 4. o get Numerator0 o get Denominator0 o These should just return the values with no changes. o setNumerator0 This should change the numerator setDenominator0 o This should change the denominator, as long as it isn't zero. If it is zero, then don't change anything, make no changes. o getDecimalValue() This should return the decimal value of the fraction 3/4 would return 0.75 o equals (Fraction other) This method should return a boolean type. This method should compare the decimal value of this fraction with the decimal value of the "other" point and see if they are equal or not
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
