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

This time we are going to take a look at an application of second order differential equations. It's now time take a look at mechanical vibrations. In exactly we are going to look

Multiply following. (a) (4x 2 -x)(6-3x) (b) (2x+6) 2 Solution  (a) (4x 2 - x )(6 - 3x ) Again we will only FOIL this one out. (4x 2  - x )(6 - 3x) = 24x 2 -

Diffrent type of rectillinar figure..

If A be the area of a right triangle and b one of the sides containing the right angle, prove that the length of the altitude on the hypotenuse is 2  Ab /√ b 4 +4A 2 . An

the size of my sitting room is 7metres by 6metres . i bought a rug for covering the centre of its floor. one metre of the floor around the edge of the room is not to be covered by

Equations of Planes Earlier we saw a couple of equations of planes.  Though, none of those equations had three variables in them and were actually extensions of graphs which we

Domain and range of a functio:  One of the more significant ideas regarding functions is that of the domain and range of a function. In simplest world the domain of function is th

Computing Limits :In the earlier section we saw that there is a large class of function which allows us to use to calculate limits. However, there are also several limits for whi

Expected Value of Perfect Information In the above problems we have used the expected value criterion to evaluate the decisions under the conditions of risk. But, as long as un