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

VECTOR, the sum of the vector QR, -SR, TQ and 2ST is?

the sum of the vector QR, -SR, TQ and 2ST is?

Relationship between inverse and sine function, Relationship between the in...

Relationship between the inverse sine function and the sine function We have the given relationship among the inverse sine function and the sine function.

Prove that a/b+c-a, a, b,c are in h.p prove that a/b+c-a, b/a+c-b, c/a+b-c ...

a, b,c are in h.p prove that a/b+c-a, b/a+c-b, c/a+b-c are in h.p To prove: (b+c-a)/a; (a+c-b)/b; (a+b-c)/c are in A.P or (b+c)/a; (a+c)/b; (a+b)/c are in A.P or 1/a; 1

Calculate the throughput and link utilization, 4. Two hosts, one on East (h...

4. Two hosts, one on East (host A) and one on the west coast (host B) of the USA are exchanging data. Suppose A is sending a large file to B. The file is split into packets of size

Equal matrices - linear algebra and matrices, I need assignment help for Eq...

I need assignment help for Equal Matrices. can you please define Equal Matrices?

Counters and registers, design a synchronous, recycling, MOD-12 counter wit...

design a synchronous, recycling, MOD-12 counter with D FF''s. Use the states 0000 through 1011 in the counter.

Volume, a data set has a mean of 3, a median of 4, and a mode of 5.which nu...

a data set has a mean of 3, a median of 4, and a mode of 5.which number must be in the data set-3,4,5?

Solid geomerty, find the equation to the sphere through the circle xsqaure+...

find the equation to the sphere through the circle xsqaure+ysquare+zsquare+=9 , 2x+3y+4z=5

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