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 many words can be formed from letters of word daughter such that each word contain 2vowles and 3consonant


for what value of k,the following system of equations have infinite solutions?kx + 5y -(k-5)=0;20x +ky - k=0

find the series of the first twenty terms

how do i solve reflection matrix just looking at the numbers in a matrix

convert the equation 4x^2+4y^2-4x-12y+1=0 to standard form and determine the center and radius of the circle. sketch the graph.

If depreciation/amortisation is done properly, impairment adjustments will not arise.   Required: Do you agree with the above statement? Critically and fully explain your

Solve discrete harmonic mapping of a given surface patch (suppose the surface is genus-0 and with one boundary) 1. Map the boundary loop onto a unit rectangle using chord-length

Chain Rule : Assume that we have two functions f(x) & g(x) and they both are differentiable. 1.   If we define F ( x ) = ( f o g ) ( x ) then the derivative of F(x) is,

Consider the function f(x) =1/2 (2 x +2 -x ) which has the graph (a) Explain why f has no inverse function. You should include an example to support your explanation