Question: Java coding please follow the following instruction Designing a Java class: A rational number is the quotient of two integers - the numerator (at the

Java coding please follow the following instruction

Designing a Java class: A rational number is the quotient of two integers - the numerator (at the top) and denominator (at the bottom). The denominator cannot be zero. Two rational numbers can be added, subtracted, multiplied and divided (I hope I dont have to tell you how). Write a java class Rational for a rational number with the following specs: A constructor that gets two integers (make sure the denominator is not 0). The numerator and denominator should be private. Getters: public int getNumerator() and public int getDenominator() Setters: public void setNumerator(int n) and public void setDenominator(int d) Public methods public Rational add(Rational r1), public Rational subtract(Rational r1), public Rational multiply(Rational r1) and public Rational divide(Rational r1). Printer function: public void print(). The number should be printed in the format n/d (numerator, forward-slash, denominator).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!