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
tan9x = (tan7x + tan2x)/(1 - tan7x*tan2x) here its given 1 - tan2x*tan7x= 0 implies tan9x = infinity since tan9x = (3tan3x - tan^3(3x))/(1 - 3tan^2 (3x)) = infinity implies

altitude 35000 @ 9:30 9;42 alt 17500 increase speed by factor of 3 level out at 2500= how much time will it take

A train goin from delhi to jaipur stops at 7 intermediate stations. 5 persons enter the train during the journey with 5 difefrent tickets of same class . How mant different set of

Fourier series - Partial Differential Equations One more application of series arises in the study of Partial Differential Equations.  One of the more generally employed method

I have about 6 Statistics questions, can anyone help me?

Find the normalized differential equation which has {x, xex} as its fundamental set

how do you change an improper fraction to a mixed number or whole or proper

INTRODUCTION : The other day I overheard 6-year-old Ahmed explaining to his older sister about why swallowing the seeds of an orange is harmful. He said, "The seed will become a p

Coal is carried from a rrrine in West Virginia to a power plant in New York in hopper cars on a long train. The automatic hopper car loader is set to put 36 tons of coal in each ca

The next kind of problem seems as the population problem. Back in the first order modeling section we looked at several population problems. In such problems we noticed a single po