Implement immutable data type rational for rational number, Mathematics

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.

 

 

Posted Date: 3/26/2013 2:34:42 AM | Location : United States







Related Discussions:- Implement immutable data type rational for rational number, Assignment Help, Ask Question on Implement immutable data type rational for rational number, Get Answer, Expert's Help, Implement immutable data type rational for rational number Discussions

Write discussion on Implement immutable data type rational for rational number
Your posts are moderated
Related Questions
Observe that natural numbers do not have a zero. This shortcoming is made good when we consider the set of whole numbers. The set of whole numbe



Union of Sets Venn diagram presenting the union of sets A and B or A?B = Shaded area is demonstrated below: A ?B = Shaded area



A fire in a building B is reported on telephone to two fire stations P and Q, 10km apart from each other on a straight road.  P observes that the fire is at an angle of 60 o to th

Find the probability of drawing a diamond card in each of the two consecutive draws from a well shuffled pack of cards, if the card drawn is not replaced after the first draw

If a tabletop has a diameter of 42 in, Detremine the surface area to the nearest inch? (π = 3.14) a. 1,384 in 2 b. 1,319 in 2 c. 1,385 in 2 d. 5,539 in 2 c. Th

what is a sample space diagram