Implement immutable data type rational for rational number, Mathematics

Assignment Help:

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.

 

 


Related Discussions:- Implement immutable data type rational for rational number

Siquence aned series, if 4,a and 16 are in the geometric sequence. Find the...

if 4,a and 16 are in the geometric sequence. Find the value

Smith keeps track of poor work, Smith keeps track of poor work. Often on af...

Smith keeps track of poor work. Often on afternoon it is 5%. If he checks 300 of 7500 instruments what is probability he will find less than 20 substandard?

One is then added to in which result what is final answer, Ten is decreased...

Ten is decreased through four times the quantity of eight minus three. One is then added to in which result. What is the final answer? The area of a square whose side measures

Probability distribution for continuous random variables, Probability Distr...

Probability Distribution for Continuous Random Variables In a continuous distribution, the variable can take any value within a specified range, e.g. 2.21 or 1.64 compared to

Invertible Matrices - Logical equivalence, 10 statements must be shown to b...

10 statements must be shown to be logically equivalent to the Statement the nxn matrix is invertible.

Graph f(x) = ex and g(x) = e- x - common graph, Graph f ( x ) = e x and g ...

Graph f ( x ) = e x and g ( x ) = e - x . Solution There actually isn't a lot to this problem other than ensuring that both of these exponentials are graphed somewhere.

Wants to Join as expert, Hi.. This is dinesh kumar I just joined experminds...

Hi.. This is dinesh kumar I just joined experminds.com , i wamt to receive assignment in maths and want to complete students assignment within time. Please help me how i can become

Scalar multiplication - vector arithmetic, Scalar Multiplication - Vector a...

Scalar Multiplication - Vector arithmetic Another arithmetic operation that we wish to look at is scalar multiplication. Specified the vector a → = (a 1 , a 2 , a 3 ) and any

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd