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

Pre calc, - Find the total surface area of a frustum of a cone. (Include to...

- Find the total surface area of a frustum of a cone. (Include top and bottom). The equation that I have for volume is v=1/3 pi x h(r^2+rR+R^2) -the equation that I have found fo

Solving equations, darien agrees to sponsor her sister $8 plus $1 for every...

darien agrees to sponsor her sister $8 plus $1 for every mile she walks.Write an expression to show her total money

Hyperbolic paraboloid- three dimensional space, Hyperbolic Paraboloid- Thre...

Hyperbolic Paraboloid- Three Dimensional Space The equation which is given here is the equation of a hyperbolic paraboloid. x 2 / a 2 - y 2 / b 2 = z/c Here is a dia

Intercepts, The last topic that we want to discuss in this section is that ...

The last topic that we want to discuss in this section is that of intercepts.  Notice that the graph in the above instance crosses the x-axis in two places & the y-axis in one plac

Complex numbers, How t determine locus of a goven point

How t determine locus of a goven point

RECTILINEAR FIGURES, AB,BC,CD ARE THREE CONSECUTIE SIDES OF REGULAR POLYGON...

AB,BC,CD ARE THREE CONSECUTIE SIDES OF REGULAR POLYGON.IF ANGLE BAC IS 18 DEGREE, FIND EXTERIOR ANGLES AND NUMBER OF SIDES ?

Word problems involving money, Word Problems Involving Money: The prom...

Word Problems Involving Money: The promoter of a track meet engages a 6,000 seat armory.  He needs to gross $15,000. The price of children's tickets is to be one-half the pric

Describe the basic concepts and terminology, Describe the Basic Concepts an...

Describe the Basic Concepts and Terminology? Somebody tells you that x = 5 and y = 3. "What does it all mean?!" you shout. Well here's a picture: This picture is what's

Utilizes the denominator for our substitution, Evaluate given integrals. ...

Evaluate given integrals.                ∫3/(5 y + 4)   dy Solution Let's notice as well that if we take the denominator & differentiate it we get only a constant and th

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