Question: Please answer the entire problem Question 1: We want to write a class for Rational numbers to be able to perform different mathematical operations such
Question 1: We want to write a class for Rational numbers to be able to perform different mathematical operations such as addition, subtraction, multiplication, and etc. Here are the methods you need to implement for this class. Class Rationall public Rational (int numerator) I/A constructor that takes an integer as an input which is equal to a rational number with denominator being 1 public Rational (int numerator, int denominator): //A constructor that takes two integers. First integer is the numerator and the second integer is the denominator of the rational number. public Rational add (Rational other) Adds two rational numbers (two objects of the Rational class) and returns a Rational public Rational sub(Rational other)i I/Subtracts two rational numbers (two objects of the Rational class) and returns a Rational. public Rational mult (Rational other) I/Multiplies two rational numbers (two objects of the Rational class) and returns a Rational. public Rational divide (Rational other) //Divides two rational numbers (two objects of the Rational class) and returns a Rational object. Division by zero is not allowed. In that case, it should print "Unexpected Error: The denominator cannot be zero" and return null. public Rational oppositeO: //Negates the rational number. public Rational invert o: //Inverts the rational number. The inverse of zero does not exist. In that case, it should print "No inverse for zero!" And return null. ctice Problems -set 3, Page 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
