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

Math, 3 9/10 into decimal

3 9/10 into decimal

Demonstrates that f ( x ) = 4 x5 + x3 + 7 x - 2 mean value, Demonstrates th...

Demonstrates that f ( x ) = 4 x 5 + x 3 + 7 x - 2 has accurately one real root. Solution From basic Algebra principles we know that since f (x) is a 5 th degree polynomi

Nonhomogeneous systems, We now require addressing nonhomogeneous systems in...

We now require addressing nonhomogeneous systems in brief. Both of the methods which we looked at back in the second order differential equations section can also be used now.  Sin

Explain introduction to non-euclidean geometry, Explain Introduction to Non...

Explain Introduction to Non-Euclidean Geometry? Up to this point, the type of geometry we have been studying is known as Euclidean geometry. It is based on the studies of the a

Toplogy, Let 0 ! V1 !    ! Vk ! 0 be a long exact sequence of vector spa...

Let 0 ! V1 !    ! Vk ! 0 be a long exact sequence of vector spaces with linear maps. Show that P (??1)i dim Vi = 0.

Polynomials, give an example of a binomial of degree 27?

give an example of a binomial of degree 27?

Pair of straight lines, the adjacent sides of a parallelogram are 2x2-5xy+3...

the adjacent sides of a parallelogram are 2x2-5xy+3y2=0 and one diagonal is x+y+2=0 find the vertices and the other diagonal

Area related to circle, If ABCD isaa square of side 6 cm find area of shad...

If ABCD isaa square of side 6 cm find area of shaded region

Lance has 70 cents margaret has 3/4 who has the most money, Lance has 70 ce...

Lance has 70 cents, Margaret has three-fourths of a dollar, Guy has two quarters and a dime, and Bill has six dimes. Who has the most money? Lance has 70 cents. Three-fourths o

Calculate probabilities, Iran is trying to decide whether it should pursue ...

Iran is trying to decide whether it should pursue its nuclear weapons program, and its decision will be affected in large measure by what it expects the United States to do. Your a

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