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
Ratio - situations in which we need to compare two quantities in terms of their ratio. (e.g., if Munna weighs 40 Kg. and Munni weighs 50 Kg., find the ratio of their weights.)

GUESS THE NUMBER THAT WHEN YOU SUBTRACT 6 AND THEN SUBTRACT 0 IS-14

Your bank has a loan outstanding with a current balance of $1,000,000 that is payable in quarterly equal instalments of $49,924.  This loan has another 6 years to maturity.  The bo

la expresión que permite calcular el radio medio de la órbita de cada planeta es?

Describe the Types of triangles ? Triangles can be classified according to the lengths of the sides or the measures of the angles. 1. Naming triangles by sides An


Q. How to calculate arithmetic average or mean? Ans. When people collect information, or data, they can easily be overwhelmed with information. Just imagine listing the b

If the areas of three adjacent faces of cuboid are x, y, z respectively, Find the volume of the cuboids. Ans: lb = x , bh = y, hl = z Volume of cuboid = lbh V 2 = l 2 b 2

From a fixed point directly in front of the center of a bull's eye, Kim aims two arrows at the bull's eye. The first arrow nicks one point on the edge of the bull's eye; the second

give me the derivation of external division of sectional formula using vectors