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

Real exponents, It is a fairly short section.  It's real purpose is to ackn...

It is a fairly short section.  It's real purpose is to acknowledge that the exponent properties work for any exponent.  We've already used them on integer and rational exponents al

Funtions, find the no of solution of 2*3*4*5*6*6

find the no of solution of 2*3*4*5*6*6

Substitutions at bernoulli equations, In the prior section we looked at Ber...

In the prior section we looked at Bernoulli Equations and noticed that in order to solve them we required to use the substitution v = y 1-n . By using this substitution we were cap

Scale Drawing, Model of 180 meter tall building using a scale of 1.5 centim...

Model of 180 meter tall building using a scale of 1.5 centimeters = 3.5 meters. How tall will the model be?

Runge kutta method, As noted, Euler's method is little used in practice, as...

As noted, Euler's method is little used in practice, as there are much better ways of solving initial value problems. By better, we mean, "able to achieve a result of the same prec

Express the gcd as a linear combination, Express the GCD of 48 and 18 as a ...

Express the GCD of 48 and 18 as a linear combination.              (Ans: Not unique) A=bq+r, where  o ≤  r 48=18x2+12 18=12x1+6 12=6x2+0 ∴ HCF (18,48) = 6 now  6

..Job, Eddie mkes $15.75 per hour. Estimate how much Eddie will make per ye...

Eddie mkes $15.75 per hour. Estimate how much Eddie will make per year if he works 40 hours per week and 50 weeks per year.

Subtraction of like terms with same signs, Suppose we are required to...

Suppose we are required to find the difference between 3abc and 7abc. We look at two scenarios. The value we would obtain by subtracting a larger quantity from th

Find out the length of hamiltonian path, Find out the length of Hamiltonian...

Find out the length of Hamiltonian Path in a connected graph of n vertices. Ans: The length of Hamiltonian Path in a connected graph of n vertices is n-1.

Differential equation and laplace transform, 1. Solve the given differentia...

1. Solve the given differential equation, subject to the initial conditions: . x2y''-3xy'+4y = 0 . y(1) = 5, y'(1) = 3 2. Find two linearly independent power series soluti

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