subject

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.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:50
What is the difference between windows 7 and windows 10?
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Now you’re on your own. include a short summary of this section with plots in your lab report. write a matlab script file to do steps (a) through (d) below. include a listing of the script file with your report. 1 the soundsc(xx,fs) function requires two arguments: the first one (xx) contains the vector of data to be played, the second argument (fs) is the sampling rate for playing the samples. in addition, soundsc(xx,fs) does automatic scaling and then calls sound(xx,fs) to actually play the signal. mcclellan, schafer, and yoder, dsp first, 2e, isbn 0-13-065562-7. prentice hall, upper saddle river, nj 07458. c 2015 pearson education, inc. 4 mcclellan, schafer and yoder, signal processing first. prentice hall, upper saddle river, new jersey, 2003. c 2003 prentice hall. (a) generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 hz sinusoids defined in the next part, part (b). use a definition for tt similar to part 2.2(d). if we use t to denote the period of the sinusoids, define the starting time of the vector tt to be equal to t , and the ending time as ct . then the two cycles will include t d 0. finally, make sure that you have at least 25 samples per period of the sinusoidal wave. in other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. (b) generate two 4000 hz sinusoids with arbitrary amplitude and time-shift. x1.t / d a1 cos.2
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
What would be the address of the cell, which is at the intersection of the second row and the third column in a worksheet?
Answers: 1
question
Computers and Technology, 24.06.2019 02:20
Peter is thinking of a number which isless than 50. the number has 9 factors.when he adds 4 to the number, itbecomes a multiple of 5. what is thenumber he is thinking of ?
Answers: 1
You know the right answer?
Write a class for the following object. Fraction - an object that represents parts of a whole numb...
Questions
question
Mathematics, 16.10.2019 01:00
question
Mathematics, 16.10.2019 01:00
question
Social Studies, 16.10.2019 01:00
Questions on the website: 13722362