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
Q. What is Factorial? A factorial is a number with a factorial sign, !, after it. 5! is read "five factorial." 3! is read "three factorial." The factorial of a natural

What is the exact vale of sin(theta/2) when sintheta=3/5, pi/2

Are there more rational numbers than integers?#

Write down the system of differential equations for the population of both predators and prey by using the assumptions above. Solution We will start off through letting that

i m making a project on share and dividend. will u pls give the all of 10pages information ?

y(x) = x -3/2 is a solution to 4x 2 y′′ + 12xy′ + 3y = 0 , y (4) = 1/8 , and y'(4) = -3/64 Solution :  As we noticed in previous illustration the function is a solution an

Allan has been hired to mow the school soccer field that is 180 ft wide through 330 ft long. If his mower mows strips which are 2 feet huge, how many times must he mow across the w

Mutually Exclusive Events A set of events is said to be mutually exclusive if the occurrence of any one of the events precludes the occurrence of any of the other events for i

Find x and y in each paarallelogram.

Q. What is Stem-and-Leaf Plots? Ans. A stem-and-leaf plot is a table that provides a quick way to arrange a set of data and view its shape, or distribution. Each data val