Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write And Fully Test A Class That Represents Rational Numbers. A Rational Number Can Be Represented As The Ratio Of Two Integer Values, A And

Write And Fully Test A Class That Represents Rational Numbers. A Rational Number Can Be Represented As The Ratio Of Two Integer Values, A And B, Where B Is Not Zero. The Class Has Attributes For The Numerator And Denominator Of This Ratio. The Ratio Should Always Be Stored In Its Simplest Form. That Is, Any Common Factor Of A And B Should Be Removed. For

image text in transcribed

 

 

 

12. Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator and denomi- nator of this ratio. The ratio should always be stored in its simplest form. That is, any common factor of a and b should be removed. For example, the rational number 40/12 should be stored as 10/3. The class has the following constructors and methods: A default constructor that sets the rational number to 0/1. A constructor that has parameters for the numerator and denominator and converts the resulting ratio to simplified form. simplify a private method that converts the rational number to sim- plified form. getGCD(x, y)-a private static method that returns the largest common factor of the two positive integers x and y, that is, their greatest common divisor. For example, the greatest common divisor of 40 and 12 is 4. getValue-returns the rational number as a double value. toString-returns the rational number as a string in the form 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

Intermediate Accounting principles and analysis

Authors: Terry d. Warfield, jerry j. weygandt, Donald e. kieso

2nd Edition

471737933, 978-0471737933

More Books

Students also viewed these Accounting questions