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 if the following sequences converge or diverge, Determine if the ...

Determine if the following sequences converge or diverge.  If the sequence converges find out its limit. a. {3n 2 - 1 / 10n + 5n 2 } ∞ n =2 b. {e 2n / n} ∞ n =1 c

Rolle''s theorem, The curve (y+1) 2 =x 2 passes by the points (1, 0) and ...

The curve (y+1) 2 =x 2 passes by the points (1, 0) and (- 1, 0). Does Rolle's Theorem clarify the conclusion that  dy dx  vanishes for some value of x in the interval -1≤x≤1?

Finding the inverse of a function , Finding the Inverse of a Function : Th...

Finding the Inverse of a Function : The procedure for finding the inverse of a function is a rather simple one although there are a couple of steps which can on occasion be somewh

Operations and properties, use an expression to write an expression with fi...

use an expression to write an expression with five 3s that has a value of 0

Evaluate the rational exponents, Evaluate each of the following.  (a) 2...

Evaluate each of the following.  (a) 25 1/2  (b) 32 1/5 Solution  (a) 25 1/2 Thus, here is what we are asking in this problem.                             2

Consecutive positive odd integers 74 what is integer value, The sum of the ...

The sum of the squares of two consecutive positive odd integers is 74. What is the value of the smaller integer? Let x = the lesser odd integer and let x + 2 = the greater odd

Irregular shapes and solids, find the area of the irregular shape 2cm 4cm 4...

find the area of the irregular shape 2cm 4cm 4cm 2cm 5cm 5cm

Evaluate infinity limit into the polynomial , Example   Evaluate following...

Example   Evaluate following limits. Solution Here our first thought is probably to just "plug" infinity into the polynomial & "evaluate" every term to finds out the

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