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

Range, identify the range of h(x)=2x+1

identify the range of h(x)=2x+1

What is the value of the lesser integer, The sum of three times a greater i...

The sum of three times a greater integer and 5 times a lesser integer is 9. Three less than the greater equivalent the lesser. What is the value of the lesser integer? Let x =

Decimals, how will the decimal point move when 245.398 is multiplied by 10

how will the decimal point move when 245.398 is multiplied by 10

Determine the probability , A medical survey was conducted in order to esta...

A medical survey was conducted in order to establish the proportion of the population which was infected along with cancer. The results indicated that 40 percent of the population

Cylinder, #question Show that the enveloping cylinder of the conicoid ax 2 ...

#question Show that the enveloping cylinder of the conicoid ax 2 + by 2 + cz 2 = 1 with generators perpendicular to the z-axis meets the plane z = 0 in parabolas

Impediments in time series analysis, Impediments in time series analysis ...

Impediments in time series analysis Accuracy of data in reflecting a) Drastic changes for illustration in the advent of a major competitor, period of war or unexpected chan

Geometry, What is the better buy?a square pizza measuring 8 inches by 8inch...

What is the better buy?a square pizza measuring 8 inches by 8inches that cost $10 or a round pizza with a 9 inch diameter that also cost $10?

Numbers, use the distributive law to write each multiplication in a differe...

use the distributive law to write each multiplication in a different way. the find the answer. 12x14 16x13 14x18 9x108 12x136 20x147

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