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
Ask question what is half of 1 1/3 liquid measurements?


If roots of (x-p)(x-q) = c are a and b what will be the roots of (x-a)(x-b) = -c please explain. Solution)  (x-p)(x-q)=c x2-(p+q)x-c=0 hence,   a+b=p+q  and    a.b=pq-c

You are given that the total frequency is 900 and the median 100.48. From the following frequency distribution, find the class frequencies that are missing. Intelligence No. of Int

Millie purchased six bottles of soda at $1.15 each. How much did she pay? To ?nd out the total cost of six bottles, you must multiply the cost per bottle through 6; $1.15 × 6 =

Mensuration surface area

Find the sum of (1 - 1/n ) + (1 - 2/n ) + (1 - 3/n ) ....... upto n terms. Ans: (1 - 1/n ) + (1 - 2/n ) - upto n terms   ⇒[1+1+.......+n terms] - [ 1/n + 2/n +....+

A school principal is looking at the combinations of subjects students are studying. He learns that the probability that a student is studying Chemistry is 0.5 and that the prob

I need help with my calculus

#question.mario has 3 nickelsin his pocket.wha fraction ofadolla do 3 nickels represent