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

Famous Numbers, Do you provide the answers to the Famous Numbers Exercise?

Do you provide the answers to the Famous Numbers Exercise?

Formula to calculate the surface area of basketball, Keith wants to know th...

Keith wants to know the surface area of a basketball. Which formula will he use? The surface area of a sphere is four times π times the radius squared.

Differance between expanded notation vs. standard notation , Differance bet...

Differance between Expanded Notation vs. Standard Notation ? A number written in expanded notation is broken down into parts just like it is in a place-value table. Example

Evaluate the volume of a ball, Evaluate the volume of a ball whose radius i...

Evaluate the volume of a ball whose radius is 4 inches? Round to the nearest inch. (π = 3.14) a. 201 in 3 b. 268 in 3 c. 804 in 3 d. 33 in 3 b. The volume of a

Introduction to learning to count, INTRODUCTION : Most of us, when plannin...

INTRODUCTION : Most of us, when planning the first mathematical experience for three-year olds, think in terms of helping them memorise numbers from 1 to 20. We also teach them to

Explain factor by grouping, Explain Factor by Grouping ? Factoring by g...

Explain Factor by Grouping ? Factoring by grouping is often a good way to factor polynomials of 4 terms or more. (Sometimes it isn't. It doesn't always work. But it's worth try

Equations and Inequalities, Write an algebraic expression for “Julie runs t...

Write an algebraic expression for “Julie runs three miles less than twice the number of miles,

Statistics, what is meant by "measure of location"

what is meant by "measure of location"

Help, question..A Circular rug is 6 yards in diameter. Binding for the edge...

question..A Circular rug is 6 yards in diameter. Binding for the edge of the rug cost $2.00 per yard . what eill it cost to bind the rug

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