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

Harmonic mean, If a, b and c are in harmonic progression with b as th...

If a, b and c are in harmonic progression with b as their harmonic mean then, b  = This is obtained as follows. Since a, b and c are in

Example for pre-operational stage learning maths, E1) I have a three-year-o...

E1) I have a three-year-old friend. He has a lot of toy cars to play with. Playing with him once, I divided the cars into two sets. One set was more spread out and had 14 cars in i

Progressions, what value of k is he sequence 2k+4,3k-7,k+12 are in an arith...

what value of k is he sequence 2k+4,3k-7,k+12 are in an arithmetic sequence is

Geometry, the figure is a rectangle with angle y=60. Find angle x

the figure is a rectangle with angle y=60. Find angle x

Adding & subtracting i guess, Jack and his mother paid $11.50 for tickets t...

Jack and his mother paid $11.50 for tickets to the movies, and adults tickets cost $4.50 more than a child ticket what was the cost of each ticket?

Determines the possibility, There is a committee to be selected comprising ...

There is a committee to be selected comprising of 5 people from a group of 5 men and 6 women. Whether the selection is randomly done then determines the possibility of having the g

Numeros naturales., Averigua que nùmero de cinco cifras se esconde detras d...

Averigua que nùmero de cinco cifras se esconde detras de las pistas dadas La cifra de las unidades es par, mayor que 6 y coincide con las decenas de mil. La cifra de las decenas se

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

Differential Equations, Verify Liouville''s formula for y "-y" - y'' + y = ...

Verify Liouville''s formula for y "-y" - y'' + y = 0 in (0, 1) ?

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