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

Fermats last theorem, Explain Fermats Last Theorem? How to solve problems u...

Explain Fermats Last Theorem? How to solve problems under Fermats Last Theorem?

Evaluate the area and perimeter of a square, Evaluate the area and perimete...

Evaluate the area and perimeter of a square: Example: Calculate the area and perimeter of a square with a = 5´.  Be sure to include units in your answer. Solution:

Marketing management , Draw the typical profile(s) of Shoppers'' Stop custo...

Draw the typical profile(s) of Shoppers'' Stop customers segments.

Write 3.5 × 104 in decimal notation, Write 3.5 × 104 in decimal notation? ...

Write 3.5 × 104 in decimal notation? Move the decimal point 4 places to the right to get 35,000.

Small samples-estimation of population mean , Estimation of population mean...

Estimation of population mean If the sample size is small (n In this case Population mean µ = x¯ ±  tS x¯  x¯ = Sample mean S x¯ =  s/√n S = standard deviation

Example of cartesian coordinate graph, Example of Cartesian coordinate Grap...

Example of Cartesian coordinate Graph: Example:   The temperature of water flowing in a high pressure line was measured at regular intervals.  Plot the subsequent recorded da

Fractions, How do you add 7/9 + 6/8 + 3/4

How do you add 7/9 + 6/8 + 3/4

Solid mensuration, a circle is circumscribed about an equilateral triangle ...

a circle is circumscribed about an equilateral triangle whose side is 3 cm. find the area of the circle.

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