Question: In Java Program 2 Construct and implement a Fraction class. A Fraction class will be used to model a fraction, such as 1:4. This class
Program 2 Construct and implement a Fraction class. A Fraction class will be used to model a fraction, such as 1:4. This class should contain member data for the namerator and the denominator Guidelines 1. Create both default and explicit constructors. 2. Create setters and getters for the data members. 3. When coding the default constructor or setter for the denominator, do not allow the denominator to be set to zero. 4. Use the test application shown below to guide you in creating your class and implementing the appropriate class methods After running this test application. public class TestApp publie statie void main(String[] args) { System.out.println("Test Application for the Praction class); // INSTANTIATE ELEVEN FRACTION OBJECTS. Traction fl-new Traction(); Fraction 12 = new Fraction (2, 7); Fraction 3 = new Fraction (4, 15); Fraction 4 new Fraction (2, 3) Fraction = new Praction (5, B): Traction 6 - new Traction (3. 10) Fraction 7 new Fraction. B) Fraction 8 - new Fraction (3.8) Fraction 19 = new Fraction (3, 18) Praction 10 = new Praction (4, 7); Fraction f11 - new Fraction(8, 14) // TASK 1: DISPLAY F1, TILSTANTIATED BY THE DEFAULT CONSTRUCTOR System.out.println("1) f1 + fi.toString() + default constructor) // TASK 2: RESET FRACTION 11 AND REDISPLAY IT 11.setNum ))) 11.setDen(5) System.out.println(2) f1 = " + F1.toString() + modified): // TASK 3: ADD FRACTION 12 TO 1 System.out.print(")". fl.tostring() + ". - 12.tostring() ...) ti.add(12): System.out.println(f1.toString()); // TASK 4: SUBTRACT 14 FROM 13 System.out.print(4) 43.tostring() - 4.toString() .. 13. subtract (14) System.out.println().toString()); // TASK 5: MULTIPLY PRACTION 5 BY F6 System.out.print(") 15.tostring() + ... + 6.toString() ) 15.multiply(16) System.out.println(5.toString()); // TASK 6: DIVIDE PRACTION ET BY 8 System.out.print("6) +17.toString() + (char) 247) +*tl.tostring 17.divide (E8) System.out.println(17.toString()); // TASK 7: REDUCE FRACTION 19 System.out.print("7) The fraction" + 19.toString() + can be reduced to: 19. reduce(): System.out.println(19.toString()) // TASK B: COMPARE FRACTIONS 110 and 111 System.out.print("8) + f10.tostring() + + 41.tostring + 10.1squali)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
