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

What is factorial, Q. What is Factorial? A factorial is a number with a...

Q. What is Factorial? A factorial is a number with a factorial sign, !, after it. 5! is read "five factorial." 3! is read "three factorial." The factorial of a natural

What is the formula to know total area square shaped quilt, Cathy is formin...

Cathy is forming a quilt out of fabric panels that are 6 in through 6 in. She needs to know the total area of her square-shaped quilt. Which formula will she use? The area of a

Probability, the probability that an account officer will pass her exam is ...

the probability that an account officer will pass her exam is 5/9. if she pass,the probability that she will be promoted is 3/4. she is not promoted if she fails her professional e

Solve 5x tan (8x ) =3x trig function, Solve 5x tan (8x ) =3x . Solution...

Solve 5x tan (8x ) =3x . Solution : Firstly, before we even begin solving we have to make one thing clear.  DO NOT CANCEL AN x FROM BOTH SIDES!!! Whereas this may appear like

Geometry, How do you solve (17+w)^2 + w^2 = (25+w)^2

How do you solve (17+w)^2 + w^2 = (25+w)^2

Proof of: limq?0 (cosq -1)/q = 0 trig limit, Proof of: lim q →0 (co...

Proof of: lim q →0 (cos q -1) / q = 0 We will begin by doing the following, lim q →0 (cosq -1)/q = lim q →0 ((cosq - 1)(cosq + 1))/(q (cosq + 1)) = lim q

Example of learning constructing tables versus rote , Maya says thafl for i...

Maya says thafl for instance, to help the children of Class 2 construct the '5 times table', she uses their hands. Each child counts how many fingers on one hand, and then how ma

Solution process of linear differential equations, For a first order linear...

For a first order linear differential equation the solution process is as given below: 1. Place the differential equation in the correct initial form, (1). 2. Determine the i

Formulas of surface area - applications of integrals, Formulas of Surface A...

Formulas of Surface Area - Applications of integrals S = ∫ 2Πyds          rotation about x-axis S = ∫ 2Πxds          rotation about y-axis Where, ds = √ 1 + (1+ (dy /

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