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
We will look at three types of progressions called Arithmetic, Geometric and Harmonic Progression. Before we start looking at the intricacies of these let us unders

"Working" definition of continuity A function is continuous in an interval if we can draw the graph from beginning point to finish point without ever once picking up our penci


Q. How to calculate Mode? The mode of a data set is the value that is repeated most often in the data set. It has the highest frequency. There can be one, more than one, or n

Normally, sets are given in the various ways A) ROASTER FORM OR TABULAR FORM In that form, we describe all the member of the set within braces (curly brackets) and differen

Q. What are Complex numbers? Ans. Complex numbers are numbers of the form a + bi, where a and b are real numbers and i is a special number called the imaginary unit, which

In a recent survey of 700 people, 15% said that red was their favorite color. How many people said that red was their favorite color? Find out 15% of 700 through multiplying 70

A framed print measures 36 by 22 in. If the print is enclosed by a 2-inch matting, Evaluate the length of the diagonal of the print? Round to the nearest tenth. See Example.