Write a class for the following object. Fraction - an object that represents parts of a whole number. A fraction is created by supplying a numerator and a denominator. Instance related actions 1. add...


Write a class for the following object.<br>Fraction - an object that represents parts of a whole number. A fraction is created by supplying a numerator and a denominator.<br>Instance related actions<br>1. add - mutates this fraction by adding the other fraction value<br>2. subtract - mutates this fraction by subtracting the other fraction value<br>3. multiply - mutates this fraction by multiplying with the other fraction value<br>4. divide - mutates this fraction by dividing by the other fraction value<br>5. tostring - represents the fraction in a form of 'numerator/denominator

Extracted text: Write a class for the following object. Fraction - an object that represents parts of a whole number. A fraction is created by supplying a numerator and a denominator. Instance related actions 1. add - mutates this fraction by adding the other fraction value 2. subtract - mutates this fraction by subtracting the other fraction value 3. multiply - mutates this fraction by multiplying with the other fraction value 4. divide - mutates this fraction by dividing by the other fraction value 5. tostring - represents the fraction in a form of 'numerator/denominator" 6. compareTo - returns the following values 1. O when this fraction is equal with the other fraction 2. 1 when this fraction is greater than the other fraction 3. -1 when this fraction is less than the other fraction Example fraction1 = 1/2 fraction2 = 3/4 When fraction1.add(fraction2] is called, it will make the value of fraction 1 as 5/4. When fraction1.subtract(fraction2) is called, it will make the value of fraction 1 as -1/4. When fraction1.multiply(fraction2) is called, it will make the value of fraction 1 as 3/8. When fraction1.divide(fraction2) is called, it will make the value of fraction 1 as 2/3. When fraction1.compareTo(fraction2) is called, it will return -1. When fraction 2.compareTo(fraction1) is called, it will return 1. Class related actions 1. add - adds 2 fractions resulting to a new fraction 2. subtract - subtracts fraction 2 from fraction 1 resulting to a new fraction 3. multiply - multiplies fraction 1 with fraction 2 resulting to a new fraction 4. divide - divides fraction 1 into fraction 2 pieces 5. greaterThen - checks whether fraction 1 is larger than fraction2 6. lessThan - checks whether fraction 1 is smaller than fraction 2 7. equals - checks if both fraction has the same value Example fraction1 = 1/2 fraction2 = 3/4 Fraction fractionSum = Fraction.add(fraction1, fraction2): // creates 5/4. Fraction fractionDifference = Fraction.subtract(fraction1, fraction 2): // creates 1/4. Fraction fractionProduct = Fraction.multiply(fraction1, fraction2); // creates 3/8. Fraction fractionQuotient = Fraction.divide(fraction1, fraction2); / creates 2/3. System.out.printIn(Fraction.greaterThan(fraction1,fraction 2)): / prints false System.out.printIn(Fraction.lessThan(fraction1,fraction2]): // prints true System.out.printIn(Fraction.equals(fraction1,fraction2)): / prints false
Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here