Computers and Technology

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.

Class related actions

add - adds 2 fractions resulting to a new fraction
subtract - subtracts fraction 2 from fraction 1 resulting to a new fraction
multiply - multiplies fraction 1 with fraction 2 resulting to a new fraction
divide - divides fraction 1 into fraction 2 pieces
greaterThen - checks whether fraction 1 is larger than fraction2
lessThan - checks whether fraction 1 is smaller than fraction 2
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, fraction2); // creates 1/4.
Fraction fractionProduct = Fraction. multiply(fraction1, fraction2); // creates 3/8.
Fraction fractionQuotient = Fraction. divide(fraction1, fraction2); // creates 2/3.
System. out. println(Fraction. greaterThan(fraction1,fraction2)); // prints false
System. out. println(Fraction. lessThan(fraction1,fraction2)); // prints true
System. out. println(Fraction. equals(fraction1,fraction2)); // prints false

Make sure that the class is encapsulated and fraction values are always in lowest terms.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:00, briannaleiigh
Kirk found a local community college with a two-year program and he is comparing the cost with that of an out-of-state two-year school. what is the expected total cost for one year at the local community college if kirk lives at home? what is the expected total cost for one year at the out-of-state school if kirk lives on campus?
Answers: 2
image
Computers and Technology, 22.06.2019 21:50, dijaflame67
Answer the following questions regarding your system by using the commands listed in this chapter. for each question, write the command you used to obtain the answer. a. what are the total number of inodes in the root filesystem? how many are currently utilized? how many are available for use? b. what filesystems are currently mounted on your system? c. what filesystems are available to be mounted on your system? d. what filesystems will be automatically mounted at boot time?
Answers: 1
image
Computers and Technology, 23.06.2019 07:00, schvox
1. you have a small business that is divided into 3 departments: accounting, sales, and administration. these departments have the following number of devices (computers, printers, etc.): accounting-31, sales-28, and administration-13. using a class c private network, subnet the network so that each department will have their own subnet. you must show/explain how you arrived at your conclusion and also show the following: all available device addresses for each department, the broadcast address for each department, and the network address for each department. also, determine how many "wasted" (not usable) addresses resulted from your subnetting (enumerate them).
Answers: 3
image
Computers and Technology, 23.06.2019 15:00, Siris420
Plz ( which is an example of a good url?
Answers: 1
Do you know the correct answer?
Write a class for the following object. Fraction - an object that represents parts of a whole numb...

Questions in other subjects: