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

Statewide mortality rates, Assume that between workers exposed to asbestos ...

Assume that between workers exposed to asbestos in a shipyard in 1980, 33 died over a 10 year period from COPD, whereas only 24 such deaths would be expected based on statewide mor

Linear probability model, Pepsi:               A dummy variable where 1 den...

Pepsi:               A dummy variable where 1 denotes choice of Pepsi by the i-th customer and 0 otherwise Price_P:           The price of a 2-liter bottle of Pepsi at the time

Adding fractions, please give the answer 1/9+1/3 with working out

please give the answer 1/9+1/3 with working out

Matric, fgdg ggghfr hhrhfrf hfrrg jhj hjgg dear friend ghr tu vgu jyyiu ui ...

fgdg ggghfr hhrhfrf hfrrg jhj hjgg dear friend ghr tu vgu jyyiu ui u huik bgyuiiyts husk

Problem word solving, Mrs. Jones and Mr. Graham had the same amount of mone...

Mrs. Jones and Mr. Graham had the same amount of money at first. After Mrs. Jones bought a computer that cost $2,055, she had 1/4 as much money as Mr. Graham. How much money di

Slope, One of the more significant ideas that we'll be discussing in this s...

One of the more significant ideas that we'll be discussing in this section is slope. The slope of a line is a measure of the steepness of any particular line and it can also be uti

Types of sets, NULL/ VOID/ EMPTY SET A set which has no element is know...

NULL/ VOID/ EMPTY SET A set which has no element is known as the null set or empty set and is indicated by f (phi). The number of elements of a set A is indicated as n (A) and

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