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

Mechanics, find the composition of the simple harmonic motion of the same p...

find the composition of the simple harmonic motion of the same period in the perpendicular directions

Exercise to think about this aspect of children- maths, Doing the following...

Doing the following exercise will give you and opportunity to think about this aspect of children. E1) List some illustrations of exploration by four or five-year-olds that you

Magnitude, find the magnitude of the following vectors:5i+7j

find the magnitude of the following vectors:5i+7j

#titlealgebra.., help solve these type equations.-4.1x=-4x+4.5

help solve these type equations.-4.1x=-4x+4.5

.fractions, what is the difference between North America''s part of the tot...

what is the difference between North America''s part of the total population and Africa''s part

Lengrange''s mean value theorem, real life applications of lengrange''s mea...

real life applications of lengrange''s mean value theorem

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