Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Please answer the entire problem
image text in transcribed
image text in transcribed
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

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