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 quadratic polynomial, Find the Quadratic polynomial whose sum and ...

Find the Quadratic polynomial whose sum and product of zeros are √2 + 1, 1/ √2 + 1 Ans:    sum = 2  √2 Product = 1 Q.P = X 2 - (sum) x + Product ∴ x 2 - (2 √2 )

VECTOR, the sum of the vector QR, -SR, TQ and 2ST is?

the sum of the vector QR, -SR, TQ and 2ST is?

Without a calculator give the exact value, without a calculator give the ex...

without a calculator give the exact value of each of the following logarithms. (a) (b) log1000 (c) log 16 16 (d) log 23 1  (e)  Solution (b) log10

The mean value theorem for integrals, The Mean Value Theorem for Integrals ...

The Mean Value Theorem for Integrals If f(x) is a continuous function on [a,b] then here is a number c in [a,b] thus, a ∫ b f(x) dx = f(c)(b -a) Proof Let's begin

Formulas, all formulas of plane figures

all formulas of plane figures

VECTORS, OQRS IS A QUADRILATERAL SUCH THAT OQ= -6,3 OR= -3,7 AND OS= 1,5. T...

OQRS IS A QUADRILATERAL SUCH THAT OQ= -6,3 OR= -3,7 AND OS= 1,5. T IS ON OQ SUCH THAT OT: TQ= 1:2 PROVE THAT QRST IS AA PARALLEGRRAM

Trigonometry, In the riangle ABC the AB=12 cm,AC=28 cm and angle ABC=120 de...

In the riangle ABC the AB=12 cm,AC=28 cm and angle ABC=120 degrees.BC=?

Case study, considring the concept of product life cycle,where would you pu...

considring the concept of product life cycle,where would you put viedo games in thier life cycle?

Parabola, please i need the answers to x^_7x+10 i want the vertex,axis of s...

please i need the answers to x^_7x+10 i want the vertex,axis of semetery,y intersect and the x intercept

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