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

Find out the next number 320, Find out the next number in the subsequent pa...

Find out the next number in the subsequent pattern. 320, 160, 80, 40, . . . Each number is divided by 2 to find out the next number; 40 ÷ 2 = 20. Twenty is the next number.

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

Calculus level 2, the first question should be done using the website given...

the first question should be done using the website given (www.desmos.com/calculator )and another good example to explain using the graph ( https://www.desmos.com/calculator/ydimzr

Progressions, The sum of the series 1+1/2+1/4,..is

The sum of the series 1+1/2+1/4,..is

Opt math, howwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...

howwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

Draw the direction field, Draw the direction field for the subsequent diffe...

Draw the direction field for the subsequent differential equation. Draw the set of integral curves for this differential equation.   Solution:  y′ = y - x  To draw direct

Perform algebraic operation , Perform each of the following algebraic expr...

Perform each of the following algebraic expression as instruction says;- I.Multiply 5x+6m+4y by5 II.Divide 4ax+6ay-10az by 2a

Important points about the alternating series test, Important Points About ...

Important Points About the Alternating Series Test There are a several things to note about this test.  Very first, unlike the Integral Test and the Comparison or Limit Compari

Wave through the origin always has a slope of one or not, Can you explain t...

Can you explain that a wave through the origin always has a slope of one or not?

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