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

Determine the equation of plane - three dimensional space, Determine the eq...

Determine the equation of the plane that consists of the points P = (1, -2, 0), Q = (3, 1, 4) and R = (0, -1, 2). Solution To write down the equation of plane there is a re

Find a minimum cost spanning arborescence rooted, Find a minimum cost spann...

Find a minimum cost spanning arborescence rooted at r for the digraph shown below, using the final algorithm shown in class.  Please show your work, and also give a final diagram w

A jeweler has bars of 18-carat gold , A jeweler has bars of 18-carat gold a...

A jeweler has bars of 18-carat gold and 12-carat gold. How much of every melted together to obtain a bar of 16-carat gold, weighing 120 gm ? It is given that pure gold is 24 carat.

Indices, 4n to the power 3/2 = 8 to the power minus 1/3. find the value of ...

4n to the power 3/2 = 8 to the power minus 1/3. find the value of n.

Making connections with maths, MAKING CONNECTIONS :  you have read about w...

MAKING CONNECTIONS :  you have read about what the ability to think mathematically involves. In this section we shall discuss ways of developing this ability in children. As yo

Geometry, Awhat is polygonesk question #Minimum 100 words accepted#

Awhat is polygonesk question #Minimum 100 words accepted#

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