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

Puzzle, 0+50x1-60-60x0+10

0+50x1-60-60x0+10

Calculate the acceleration time, Question A 22 kW, 3-phase, 415 V, 40 A,...

Question A 22 kW, 3-phase, 415 V, 40 A, 50 Hz, 960 rpm, 0.88 PF squirrel cage induction motor drives a pump. The total inertia of the drives system is 1.2 kg-m2. Determine th

Operation research, discuss the sequencing decision problem for n jobs on t...

discuss the sequencing decision problem for n jobs on two and three machines

Linear programming, #question.As office manager of her firm, Marcellyne has...

#question.As office manager of her firm, Marcellyne has been directed to buy new filing cabinets. She knows that cabinet A costs $10, requires 6 square feet of floor space, and hol

What is the meaning of the f-statistic and f test, You are given the follow...

You are given the following regression results estimating the demand for widgets based on time series data for the past 40 months. Q t = 2.5 - 0.3 x P t + 12 x M t Where Q

Determine the conditional probability, Consider a class of 55 students. The...

Consider a class of 55 students. The student names are placed in a hat and 3 names are randomly drawn without replacement. a) If the first person drawn was named the class presi

Utilizes the denominator for our substitution, Evaluate given integrals. ...

Evaluate given integrals.                ∫3/(5 y + 4)   dy Solution Let's notice as well that if we take the denominator & differentiate it we get only a constant and th

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

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

Find the shortest paths in the digraph, 1. a) Find the shortest paths from ...

1. a) Find the shortest paths from r to all other nodes in the digraph G=(V,E) shown below using the Bellman-Ford algorithm (as taught in class).  Please show your work, and draw t

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