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

What is dividing fractions, What is Dividing Fractions? If you want to ...

What is Dividing Fractions? If you want to divide two fractions, you invert the second fraction (that is, turn it upside-down) and change the division sign to a multiplication

Interpretations of derivatives, Interpretations of derivatives. Exampl...

Interpretations of derivatives. Example:   Find out the equation of the tangent line to                                       x 2 + y 2   =9 at the point (2, √5 ) .

Integrated marketing, #question.Explain its nature and how it influences th...

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

Order of a differential equation, The order of a differential equation is t...

The order of a differential equation is the huge derivative there in the differential equation. Under the differential equations as listed above in equation (3) is a first order di

Find extrema & relative extrema f ( x ) = x3 on [-2, Recognizes the absolut...

Recognizes the absolute extrema & relative extrema for the given function.                                                    f ( x ) = x 3      on        [-2, 2] Solution :

Ratio math help, Mr.Tanaka has 56 students in his choir the ratio of boys ...

Mr.Tanaka has 56 students in his choir the ratio of boys to girls is 3:4 how many boys and girls are in his class

Create a circular table with no restrictions, 1. Four different written dri...

1. Four different written driving tests are administered by a city. One of these tests is selected at random for each applicant for a drivers license. If a group of 2 women and 4 m

#title, how do you do hard math!!!

how do you do hard math!!!

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