Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Public Methods getDenominator - This is a getter method used to retrieve the denominator. method receives no parameters and returns an integer. This getNumerator- This

image text in transcribed
Public Methods getDenominator - This is a "getter" method used to retrieve the denominator. method receives no parameters and returns an integer. This getNumerator- This is a "getter" method used to retrieve the numerator. This method receives no parameters and returms an integer. add - This method should receive a single rational number as a parameter. It should add the parameter to the current (this) object and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. For example, suppose x is the rational number "34", and y is the rational number "S/6", and z is a rational mumber. The command z x.add (y) should return the - rational number "38/24" and store it in z. x should not be changed by this method, and y should not be changed by this method Refer to the formulas listed below to find out how to add two rational numbers. sub - This method should receive a single rational number as a parameter. It should subtract the parameter from the current (this) object and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. For example, suppose x is the rational number "34", and y is the rational mumber "S/6", and z is a rational number. The command z - y.sub (x) should return the rational number "2/24" and store it in z x should not be changed by this method, and y should not be changed by this method mul - This method should receive a single rational number as a parameter. It should multiply the current (this) object by the parameter and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. div - This method should receive a single rational number as a parameter. It should divide the current (this) object by the parameter and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. neg - This method will take no parameters. It should negate the current (tkhis) object and return the answer as a new rational number object. The current object should not be changed by this method. For example, suppose x is the rational number "34", and z is a rational number. The command z - x.neg () should return the rational number "-34" and store it in z Formulas Use the following formulas for the computations performed by the methods. In cach of these formulas "A" is a numerator, and "B" is a denominator for one of the rational mumbers, "C is the numerator and "D" is the denominator for the second rational number. Also remember that since these are rational numbers, the division is not actually performed. Therefore, in the formulas, wherever you see a "division symbol", you don't actually perform the division the "division symbol" is used in rational numbers to separate the numerator from the denominator. The only exception is on the left-side of the equals sign in the division formula where there is a division symbol used to indicate that we are trying to divide two rational numbers. Addition: (A/B) + (C/D) - (AD + B*C)/ (B*D) Subtraction: (A/B) - (C/D) - (A*D - B*C) / (B*D) Multiplication: (A/B). (C/D) - (A*C) / (B*D) Division: (A/B)/ (C/D)- (A D) / (B C) Negation: - (A/B) - ((-A) /B) Public Methods getDenominator - This is a "getter" method used to retrieve the denominator. method receives no parameters and returns an integer. This getNumerator- This is a "getter" method used to retrieve the numerator. This method receives no parameters and returms an integer. add - This method should receive a single rational number as a parameter. It should add the parameter to the current (this) object and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. For example, suppose x is the rational number "34", and y is the rational number "S/6", and z is a rational mumber. The command z x.add (y) should return the - rational number "38/24" and store it in z. x should not be changed by this method, and y should not be changed by this method Refer to the formulas listed below to find out how to add two rational numbers. sub - This method should receive a single rational number as a parameter. It should subtract the parameter from the current (this) object and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. For example, suppose x is the rational number "34", and y is the rational mumber "S/6", and z is a rational number. The command z - y.sub (x) should return the rational number "2/24" and store it in z x should not be changed by this method, and y should not be changed by this method mul - This method should receive a single rational number as a parameter. It should multiply the current (this) object by the parameter and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. div - This method should receive a single rational number as a parameter. It should divide the current (this) object by the parameter and return the answer as a new rational number object. Neither the current object, nor the parameter should be changed by this method. neg - This method will take no parameters. It should negate the current (tkhis) object and return the answer as a new rational number object. The current object should not be changed by this method. For example, suppose x is the rational number "34", and z is a rational number. The command z - x.neg () should return the rational number "-34" and store it in z Formulas Use the following formulas for the computations performed by the methods. In cach of these formulas "A" is a numerator, and "B" is a denominator for one of the rational mumbers, "C is the numerator and "D" is the denominator for the second rational number. Also remember that since these are rational numbers, the division is not actually performed. Therefore, in the formulas, wherever you see a "division symbol", you don't actually perform the division the "division symbol" is used in rational numbers to separate the numerator from the denominator. The only exception is on the left-side of the equals sign in the division formula where there is a division symbol used to indicate that we are trying to divide two rational numbers. Addition: (A/B) + (C/D) - (AD + B*C)/ (B*D) Subtraction: (A/B) - (C/D) - (A*D - B*C) / (B*D) Multiplication: (A/B). (C/D) - (A*C) / (B*D) Division: (A/B)/ (C/D)- (A D) / (B C) Negation: - (A/B) - ((-A) /B)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

Students also viewed these Databases questions

Question

3. Is IBMs program really a mentoring program? Why or why not?

Answered: 1 week ago