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

Explain what is symmetry in maths, Symmetry Definition : A line of sy...

Symmetry Definition : A line of symmetry divides a set of points into two halves, each being a reflection of the other. Each image point is also a point of the set. Defin

Free - undamped vibrations, It is the simplest case which we can consider. ...

It is the simplest case which we can consider. Unforced or free vibrations sense that F(t) = 0 and undamped vibrations implies that g = 0. Under this case the differential equation

Fractions, which fractions is equivalent to 5/ 6 a.20/24 b.9/10 c.8/18 d....

which fractions is equivalent to 5/ 6 a.20/24 b.9/10 c.8/18 d.10/15

What is trigonometric ratios, What is Trigonometric Ratios ? Trigonome...

What is Trigonometric Ratios ? Trigonometry, a branch of mathematics, is based on the ratios known as sine, cosine, and tangent. Trigonometric ratios apply only to right trian

Normal Distribution, You don''t have to give me the answer. I just want to ...

You don''t have to give me the answer. I just want to know HOW to do it. In a set of 400 ACT scores where the mean is 22 and the standard deviation is 4.5, how many scores are ex

Find out arc length - applications of integrals, Find out the length of y =...

Find out the length of y = ln(sec x ) between 0 x π/4. Solution In this example we'll need to use the first ds as the function is in the form y = f (x). So, let us g

Decision-making under conditions of risk, Decision-making Under Conditions ...

Decision-making Under Conditions of Risk With decision-making under conditions of risk all possible states of nature are known and the decision maker has sufficient knowledge

Calculate one-sided limits, Calculate the value of the following limits. ...

Calculate the value of the following limits. Solution From the graph of this function illustrated below, We can illustrate that both of the one-sided limits suffer

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