Implement immutable data type rational for rational number, Mathematics

Assignment Help:

Implement an immutable data type Rational for rational numbers that supports addition, subtraction, multiplication and division.

public class Rational


Rational(int numerator, int denominator)

Rational

plus(Rational b)

sum of this number and b

Rational

minus(Rational b)

difference of this number and b

Rational

times(Rational b)

product of this number and b

Rational

divides(Rational b)

quotient of this number and b

boolean

equals(Rational that)

is this number equal to that?

String

toString()

string representation

Notes

  1. You do not have to worry about testing for overflow, but use as instance variables two long values that represent the numerator and denominator to limit the possibility of overflow.
  2. Use Euclid's algorithm to ensure that the numerator and denominator never have any common factors.
  3. Include a test client that exercises all of your methods.

 

 


Related Discussions:- Implement immutable data type rational for rational number

Find the coordinates of the other two vertices, The two opposite vertices o...

The two opposite vertices of a square are (-1, 2) and (3, 2). Find the coordinates of the other two vertices.

How much money did carlie have after she had paid her friend, Carlie receiv...

Carlie received x dollars every hour she spent babysitting. She babysat a total of h hours. She then gave half of the money to a friend who had stopped through to help her. How muc

How much does every person required to pay rob, Rob purchased picnic food f...

Rob purchased picnic food for $33.20 to share along with three of his friends. They plan to split the cost evenly among the four friends. How much does every person required to pay

Fractions, A car travels 283 1/km in 4 2/3 hours .How far does it go in 1 h...

A car travels 283 1/km in 4 2/3 hours .How far does it go in 1 hour?

Estimate the area between f ( x ) =x3 - 5x2 + 6 x + 5, Estimate the area be...

Estimate the area between f ( x ) =x 3 - 5x 2 + 6 x + 5 and the x-axis by using n = 5 subintervals & all three cases above for the heights of each of the rectangle. Solution

Purely imaginary number, It is totally possible that a or b could be zero a...

It is totally possible that a or b could be zero and thus in 16 i the real part is zero.  While the real part is zero we frequently will call the complex numbers a purely imaginar

Extrema- minimum and maximum values, Extrema : Note as well that while we ...

Extrema : Note as well that while we say an "open interval around x = c " we mean that we can discover some interval ( a, b ) , not involving the endpoints, such that a Also,

How to convert percentages to decimals, Q. How to Convert Percentages to De...

Q. How to Convert Percentages to Decimals? Ans. Since percent stands for "hundredths", to write a percentage as a decimal you just need to find how many hundredths it repr

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd