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

Maths question, if the numerator of a fraction is decreased by 40% and the ...

if the numerator of a fraction is decreased by 40% and the denominator is increased by 100% the new value is 1. what was the original factor

I need help in math badly, I just have a hard time in math in every other c...

I just have a hard time in math in every other class I have an A or B but in math I have a C+ I at least want a B- or B+ or A- or even an A+

Mean is 8.32 find the median, In a frequency distribution mode is 7.88, mea...

In a frequency distribution mode is 7.88, mean is 8.32 find the median.  (Ans: 8.17) Ans:  Mode = 3 median - 2 mean 7.88 = 3 median - 2 x 8.32 7.88 +16.64 = 3 median

Logarithms, How to solve this: log x(81) = 4

How to solve this: log x(81) = 4

Guess my number, My thousandths digit is twice the tenths digit. My tenths ...

My thousandths digit is twice the tenths digit. My tenths digit is one less than the hundredths digit. If my number is 5, what my number?

Describe order of operations with example, Describe Order of Operations wit...

Describe Order of Operations with example? The order of operations is a set of rules that describe the order in which math operations are done. Try doing this math problem:

Chi square distribution, Chi Square Distribution Chi square was first ...

Chi Square Distribution Chi square was first utilized by Karl Pearson in 1900. It is denoted by the Greek letter χ 2 . This contains only one parameter, called the number of d

Find the area irrigated by this system, An irrigation system uses a straigh...

An irrigation system uses a straight 30m sprinkler pipe which is capped at one end and arranged so that all water is released directly downwards and pivots around a central point.

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