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

Sketch the hyperbolic spiral-spiral of archimedes, 1. Sketch the Spiral of ...

1. Sketch the Spiral of Archimedes: r= aθ (a>0) ? 2: Sketch the hyperbolic Spiral: rθ = a (a>0) ? 3: Sketch the equiangular spiral: r=ae θ (a>0) ?

Theorem on intervals of validity, Theorem Consider the subsequent IVP....

Theorem Consider the subsequent IVP. y′ =  p (t ) y = g (t )  y (t 0 )= y 0 If p(t) and g(t) are continuous functions upon an open interval a o , after that there i

Solutions to systems, Now that we've found some of the fundamentals out of ...

Now that we've found some of the fundamentals out of the way for systems of differential equations it's time to start thinking about how to solve a system of differential equations

Find the cost price of the toy, A dealer sells a toy for Rs.24 and gains as...

A dealer sells a toy for Rs.24 and gains as much percent as the cost price of the toy. Find the cost price of the toy. Ans:    Let the C.P be x ∴Gain = x % ⇒ Gain = x

Additionally functions in substitution rule, Substitution Rule Mostly ...

Substitution Rule Mostly integrals are fairly simple and most of the substitutions are quite simple. The problems arise in correctly getting the integral set up for the substi

Help, Two sessions of swimming lessons were held at a pool. In the first se...

Two sessions of swimming lessons were held at a pool. In the first session 40 students attended. Of these 40 students 60% were girls. How many girls attended the first session of s

Comperative statics, Discuss comparative statics,Market model and Nationa i...

Discuss comparative statics,Market model and Nationa income model

Area problem, Area Problem Now It is time to start second kind of inte...

Area Problem Now It is time to start second kind of integral: Definite Integrals.  The area problem is to definite integrals what tangent & rate of change problems are to d

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