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

Laplace transforms, As we saw in the previous section computing Laplace tra...

As we saw in the previous section computing Laplace transforms directly can be quite complex. Generally we just utilize a table of transforms when actually calculating Laplace tran

Least common denominator using primes, Least Common Denominator Using Prime...

Least Common Denominator Using Primes: A prime number is a whole number (integer) whose only factors are itself and one. So the first prime numbers are given as follows: 1,

Matrices, Ask qudefination of empty matrixestion #Minimum 100 words accepte...

Ask qudefination of empty matrixestion #Minimum 100 words accepted#

Maths, f all the permutations of the letters of the word chalk are written ...

f all the permutations of the letters of the word chalk are written in a dictionary the rank of this word will be?

Example of problems related to applying operations, I had just come back fr...

I had just come back from a very interesting talk arranged by a Mathematics Centre, it was aimed at parents of primary school-going children. They had talked about, and demonstrate

About matrix?, Explain sparse matrix and Dense matrix?

Explain sparse matrix and Dense matrix?

Given x+1/x=2cosy then find x^n +1/x^n, Here we know x can only be 1 or -1...

Here we know x can only be 1 or -1. so if it is 1 ans is 2. if x is -1, for n even ans will be 2 if x is -1 and n is odd ans will ne -2. so we can see evenfor negative x also an

Speed, how much distance is covered by a man if he is travelling at a speed...

how much distance is covered by a man if he is travelling at a speed of 45km/h in 5 sec

Describe the introduction to integers, Describe the Introduction to Integer...

Describe the Introduction to Integers ? Integers include the positive and negative whole numbers, such as -4, -3, -2, -1, 0, 1, 2, 3, 4, and so on. A negative number has 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