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
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