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

Probability., an insurance salesman sells policies to 5 men, all of identic...

an insurance salesman sells policies to 5 men, all of identical age in good health. the probability that a man of this particular age will be alive 30 years hence is 2/3.Find the p

Debate over answer to an equation..., The math equation is written exactly ...

The math equation is written exactly this way: 0+50x1-60-60x0+10=??? The answer I get is 10 and others say 0 0+50=50 50x1=50 50-60=-10 -10-60=-70 -70x0=0 0+10=10

., Two boys A and B are at two diametrically opposite points on a circle. A...

Two boys A and B are at two diametrically opposite points on a circle. At one instant the two start running on the circle; A anticlockwise with constant speed v and B clockwise wit

Randy, write in factor form 9x3+9x5

write in factor form 9x3+9x5

Find relation between x and y while lies on straight line, Find the relatio...

Find the relation between x and y when the point (x,y) lies on the straight line joining the points (2,-3) and (1,4) [ Hint: Use area of triangle is 0] Ans :   Hint: If the poi

Ryan gym membership costs him how much is every installment, Ryan's gym mem...

Ryan's gym membership costs him $390 per year. He pays this within twelve equal installments a year. How much is every installment? To ?nd out each installment, the total yearl

Definition of a function, A function is a relation for which each of the va...

A function is a relation for which each of the value from the set the first components of the ordered pairs is related with exactly one value from the set of second components of t

Graphing , what effect is the constant in an equation have on an graph

what effect is the constant in an equation have on an graph

Applied Math, Calucations of gradients find f Graph some level curve f=cons...

Calucations of gradients find f Graph some level curve f=const. f=9x^2 = 4y^2

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