Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Rational numbers should be stored in reduced form with any negative sign stored only on the numerator (i.e. the denominator must be positive). Your toString

image text in transcribed

Rational numbers should be stored in reduced form with any negative sign stored only on the numerator (i.e. the denominator must be positive). Your toString method should omit denominators of 1. You will need to include methods for add, subtract, multiply, and divide. Use your class to build a simple text-based calculator for Rational Numbers. Your calculator should accept commands to give help (i.e. list valid commands and give usage information), clear the current accumulator, set the accumulator to a new value, negate the accumulator, add, subtract, multiply or divide, the accumulator by a given rational number. The accumulator should start at 0 and be printed after each command.

java programming language

dlass called RationalNumber that represents a fraction with an integer numerator and denominator. tonal Number object should have the following methods: RationalNumber(int numerator, int denominator) A Rat new rational number to represent the ratio (numerator/denominator). The denominator cannot be 0, so throw an IllegalArgumentException if o is passed. public RationalNumber() Constructs a new rational number to represent the ratio (0/1n). public int getDenominator() Returns this rational number's denominator value; for example, if the ratio is (3/5), returns 5. public int getNumerator () Returns this rational number's numerator value; for example, if the ratio is (3/5), returns 3. public String tostring() Returns a String representation of this rational number, such as "3/5". You may wish to omit denominators of 1, returning "4" instead of "4/1". An extra challenge would be to maintain your Rationa1 Number objects in reduced form, avoiding rational numbers such as 3/6 in favor of 1/2, or avoiding 2/-3 in favor of-2/3. Another possible extra feature would be methods to add, subtract, multiply, and divide two rational numbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions