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 the value of ((a+b)/(a-b)) , If arg (a/b) = pi/2, then find the value ...

If arg (a/b) = pi/2, then find the value of ((a+b)/(a-b)) where a,b are complex numbers. Ans) Arg (a/b) =Pi/2 Tan-1   (a/b)=   Pi/2 A/B = tanP/2 ,therefore a/b=infinity.

Fact of the wronskian method, Given two functions f(x) and g(x) which are d...

Given two functions f(x) and g(x) which are differentiable on some interval I  (1) If W (f,g) (x 0 ) ≠ 0 for some x 0 in I, so f(x) and g(x) are linearly independent on the int

RATIO, 3 years to 104 weeks,express answer in ratio

3 years to 104 weeks,express answer in ratio

Transportation problem, matlab code for transportation problem solved by vo...

matlab code for transportation problem solved by vogel''s approximation method

Outer automorphism, (a) An unordered pair fm; ng with 1 ≤ m ≠ n ≤ 6 is ca...

(a) An unordered pair fm; ng with 1 ≤ m ≠ n ≤ 6 is called a duad. List the 15 duads. (b) There are 15 ways to partition {1, ......, 6 } into 3 duads, such as { {1; 2}, {3, 4},

Differential equation, Cos(x+y)+sin(x+y)=dy/dx(solve this differential equa...

Cos(x+y)+sin(x+y)=dy/dx(solve this differential equation)

Evaluate indefinite integrals, Evaluate following indefinite integrals. ...

Evaluate following indefinite integrals.  (a) ∫ 5t 3 -10t -6 + 4 dt  (b) ∫ dy Solution  (a) ∫ 5t 3 -10t -6 + 4 dt There's not whole lot to do here other than u

Dropped down the rational expression to lowest terms, Carry out the indicat...

Carry out the indicated operation and dropped down the answer to lowest terms.  (x 2 - 5x -14/ x 2 -3x+2) .   (x 2 - 4)/x 2 -14x+49) Solution This is a multiplication.

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