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

Geometry, triangular with base AB = 48cm and height CH=16cm is inscribed a ...

triangular with base AB = 48cm and height CH=16cm is inscribed a rectangle MNPQ in which MN: MQ = 9:5 Find MN and MQ

Factoring out a common monomial factor, Factoring Out a Common Monomial Fac...

Factoring Out a Common Monomial Factor? Say you have a polynomial, like 3x 4 y - 9x 3 y + 12x 2 y2 z and you want to factor it. Your first step is always to look for t

Proof for properties of dot product, Proof for Properties of Dot Product ...

Proof for Properties of Dot Product Proof of u → • (v → + w → ) = u → • v → + u → • w → We'll begin with the three vectors, u → = (u 1 , u 2 , ...

Algebraic number, prove that every non-trivial ingetral solution (x,y,z)of ...

prove that every non-trivial ingetral solution (x,y,z)of the diophantine equation Xsquare +Ysquare=Zsquare satisfies gcd(x,y)=gcd(x,z)=gcd(y,z)

Pre-calculus, Give all solutions between o degree and 360 degree for sin x=...

Give all solutions between o degree and 360 degree for sin x=3/2

Stat, defination of uper boundarie .

defination of uper boundarie .

What is congruent angles in parallel lines, What is Congruent Angles in Par...

What is Congruent Angles in Parallel Lines ? Postulate 4.1 (The Parallel Postulate) Through a given point not on a line there is exactly one line parallel to the line. T

Integraton, how to find area under a curve

how to find area under a curve

Calculate the probability, Calculate the introduction to Probability? P...

Calculate the introduction to Probability? Probability refers to the chance that an event will happen. Probability is presented as the ratio of the number of ways an event can

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