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

Properties of the indefinite integral, Properties of the Indefinite Integra...

Properties of the Indefinite Integral 1.  ∫ k f ( x ) dx = k ∫ f ( x ) dx where k refer for any number.  Thus, we can factor multiplicative constants out of indefinite integral

Show basic trigonometric functions, Q. Show basic Trigonometric Functions? ...

Q. Show basic Trigonometric Functions? Ans. There are six trigonometric functions and they can be defined using a right angle triangle. We first label each side according

Two consecutive positive integers whose product is 90, What is the lesser o...

What is the lesser of two consecutive positive integers whose product is 90? Let x = the lesser integer and let x + 1 = the greater integer. Because product is a key word for m

What are the characteristics of a queuing system, What are the characterist...

What are the characteristics of a queuing system?  (i) The input pattern  (ii) The queue discipline  (iii) The service mechanism

Measurement, into how many smaller part is each centimeter divided

into how many smaller part is each centimeter divided

Find out the area under the parametric curve, Find out the area under the p...

Find out the area under the parametric curve given by the following parametric equations.  x = 6 (θ - sin θ) y = 6 (1 - cos θ) 0 ≤ θ ≤ 2Π Solution Firstly, notice th

Comparison-types of word problems related to subtraction, Comparison - the...

Comparison - the difference between two groups or numbers, namely, how much one is greater than the other, how much more is in one group than in the other. (e.g., if Munna has

What is the integratin of 1/sin2x?, ∫1/sin2x dx = ∫cosec2x dx = 1/2 log[cos...

∫1/sin2x dx = ∫cosec2x dx = 1/2 log[cosec2x - cot2x] + c = 1/2 log[tan x] + c Detailed derivation of ∫cosec x dx = ∫cosec x(cosec x - cot x)/(cosec x - cot x) dx = ∫(cosec 2 x

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