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
Megan bought x pounds of coffee in which cost $3 per pound and 18 pounds of coffee at $2.50 per pound for the company picnic. Find out the total number of pounds of coffee purchase

Translate the following formula into a prefix form expression in Scheme: 5+4*(6-7/5)/3(14-5)(3+1)

I need help trying to compare 10/15 and 8/12

Magnitude - Vector The magnitude, or length, of the vector v → = (a1, a2, a3) is given by, ||v → || = √(a 1 2 + a 2 2 + a 2 3 ) Example of Magnitude Illus

If the points for a right angle triangle are XYZ where do I mark the points?

MATHEMATICS - IN OUR LIVES : What is the most obvious example of mathematics in your life? To many of us it is the maths that we studied in school. But is that all the mathemat

An investment advisory firm manages funds for its numerous clients. The company uses an asset allocation model that recommends the portion of each client's portfolio to be invested

#How are Indian customers visiting Shoppers’ Stop any different from customers of developed western countries?

Evaluate following integrals.                       ( (1 - (1 /w) cos (w - ln w) dw Solution In this case we know how to integrate only a cosine therefore let's makes th

Area with Polar Coordinates In this part we are going to look at areas enclosed via polar curves.  Note also that we said "enclosed by" in place of "under" as we usually have