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
Discontinuous Integrand- Integration Techniques Here now we need to look at the second type of improper integrals that we will be looking at in this section.  These are integr

do you have a decimal place value chart

Type I and type II errors When testing hypothesis (H 0 ) and deciding to either reject or accept a null hypothesis, there are four possible happenings. a) Acceptance of a t

#question.Explain its nature and how it influences the integrated marketing communications mix and distinguish between tactical and strategic use of integrated marketing communicat

i really ned help wiv quartiles plz help

i dont now how to do it

1.A=the set of whole numbers less tan 4 ? 2.B=the set of prime numbers less than 19 ? 3.C=the set of first three days of week?

Find the sum of all natural numbers amongst first one thousand numbers which are neither divisible 2 or by 5 Ans:    Sum of all natural numbers in first 1000 integers which ar

How do you find the ratio for these problems?

A telephone dialled is numbered 0to9. if 0is dialled first the caller is connected to the international exchange system.find the number of local calls that can be rung if a local n