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
HOW DOES A CHILD THINK? :  You must have interacted with children of various ages. From your experience, do you feel that children start learning, from a very early age, and conti


Evaluate the given definite integral. Solution                      Let's begin looking at the first way of dealing along with the evaluation step. We'll have to be c

the sum of the vector QR, -SR, TQ and 2ST is?

Differentiate following functions.                       h (t ) = 2t 5 + t 2 - 5 / t 2 We can simplify this rational expression as follows.                       h (t )

Differentials : In this section we will introduce a notation. We will also look at an application of this new notation. Given a function y = f ( x ) we call dy & dx differen

Problem 1. Find the maximum and the minimum distance from the origin to the ellipse x 2 + xy + y 2 = 3. Hints: (i) Use x 2 + y 2 as your objective function; (ii) You c

Forecasting By Using Least Squares Data have been kept of sales over the last seven years Year 1 2 3 4 5 6

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

If 28,000 = 85% and 28,000 / X = 100%. What the freak is X and how do you work it out.