Question
Can anyone please help me with this homework assignment. I am new to java programming. Java programming language Question: Write a class called RationalNumber that
Can anyone please help me with this homework assignment. I am new to java programming. Java programming language Question:
Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. public RationalNumber(int numerator, int denominator) Constructs a new rational number to represent the ratio. the denominator cannot be 0, show an illegalArgumentException if 0 is passed. public RationalNumber() public getDenominator() public getNumerator() 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".
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started