subject

Java Program 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

add - mutates this fraction by adding the other fraction value
subtract - mutates this fraction by subtracting the other fraction value
multiply - mutates this fraction by multiplying with the other fraction value
divide - mutates this fraction by dividing by the other fraction value
toString - represents the fraction in a form of "numerator/denominator"
compareTo - returns the following values
0 when this fraction is equal with the other fraction
1 when this fraction is greater than the other fraction
-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 fraction2.compareTo(fraction1) is called, it will return 1.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 01:30
Write a program that asks the user to enter the name of an input file. if the file does not exist, the program should prompt the user to enter the file name again. if the user types quit in any uppercase/lowercase combinations, then the program should exit without any further output.
Answers: 3
question
Computers and Technology, 24.06.2019 18:30
Jacking is a crime that takes place when a hacker misdirects url to a different site. the link itself looks safe, but the user is directed to an unsafe page
Answers: 1
question
Computers and Technology, 24.06.2019 19:20
Which command suppresses the visibility of a particular row or column in a worksheet?
Answers: 1
question
Computers and Technology, 24.06.2019 20:30
Which key should you press to leave the cell as it originally was? a. delete b. cancel c. backspace d. enter
Answers: 1
You know the right answer?
Java Program Write a class for the following object.

Fraction - an object that represe...
Questions
question
Health, 12.05.2021 01:50
question
Chemistry, 12.05.2021 01:50
Questions on the website: 13722359