Question: (COMPLETE IN JAVA & explain step by step) 1.2.16 Rational numbers. Implement an immutable data type Rationa 1 for rational numbers that supports addition, subtraction,

(COMPLETE IN JAVA & explain step by step)(COMPLETE IN JAVA & explain step by step) 1.2.16 Rational numbers. Implement

an immutable data type Rationa 1 for rational numbers that supports addition,

1.2.16 Rational numbers. Implement an immutable data type Rationa 1 for rational numbers that supports addition, subtraction, multiplication, and division. You do not have to worry about testing for overflow (see EXERCISE 1.2.17), but use as instance variables two 7 ong values that represent the numerator and denominator to limit the possibility of overflow. Use Euclid's algorithm (see page 4) to ensure that the numerator and denominator never have any common factors. Include a test client that exercises all of your methods. Do the Creative Problems Exercise \# 1.2.16: Rational Numbers on page 117: 1.2.16 Rational numbers. 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 You do not have to worry about testing for overflow (see Exercise 1.2.17), but use as instance variables two long values that represent the numerator and denominator to limit the possibility of overflow. Use Euclid's algorithm (see page 4) to ensure that the numerator and denominator never have any common factors. Include a test client that exercises all of your methods. Euclid's Algorithm: public static int gcd(int p, int q) \{ if (q==0) return p; int r=p%q; return gcd(q,r); \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!