Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use java . Very similar to assignment #19. for this assignment I want you to write a Fraction class that works with the FractionMath

please use java image text in transcribed
image text in transcribed
image text in transcribed
. Very similar to assignment #19. for this assignment I 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 Fraction class should have the following . Fields a numerator (int) a denominator (int) Methods A default constructor . that sets the numerator to 1 that sets the denominator to 1 A full constructor . That accepts both the numerator and denominator. . Note that if the denominator is zero, you should change it to a 1. . A toString() method . That returns a string in the format Ispace) numerator / denominator space] 2/5 . however, if the denominator is 1, then the fraction is a whole number so you should just return the numerator . Le do not print 4/1 just print 4. getNumerator getDenominator .. These should just return the values with no changes setNumerator . This should change the numerator .setDenominator . This should change the denominator, as long as it isn't zero. If the new value is zero then don't change anything. make no changes and leave it where it was getDecimalValue . This should return the decimal value of the fraction . 3/4 would return 0.75 equals (Fraction other) . This method should return a boolean type . This method should compare the decimal value of this fraction with the decimat value of the other point and see if they are equal or not. . If equal return true, else return false; multiply(Fraction other . This method should take the current fraction and multiple it by the "other" fraction and change the value to the new fraction. . So if x - 2/5 andy - 3/4 . then x.multiplyly! . would change x to 6/20 . but leave y as 3/4 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 2 = new Fraction(6.0); over + W): 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 : " + 2); System.out.println(); // Does the get() method work? System.out.println("*** Does the get() methods work?"); System.out.println("w = " + w.get Numerator() + + 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.setDenominator (55); System.out.println("w fraction After w.setDenominator (o); 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" egaul to +y+""); System.out.println(" +w.equals()); System.out.println(); // Does the getDecimal work System.out.printf(x + " = 54.2f $n", x.getDecimalValue()); System.out.printf(y + " = $4.2f %n". y.getDecimalvalue()); System.out.printf(z + " = 34.2f %n", z.getDecimalvalue(); System.out.println(); 1/ Does the multiply work System.out.println("x fraction Before : System.out.println("y fraction Before :" + y); 21 . . + X) y); - x.multiply(); System.out.println("x fraction After System.out.println("y fraction After System.out.println("*** Test #2 ***"); System.out.println("y fraction Before System.out.println(" fraction Before y.multiply(z); System.out.println("y fraction After System.out.println("z fraction After : y); 2); : : + y); + 2); } )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions