A rational number is the quotient of two integers - the numerator and denominator. The denominator cannot be zero. Two rational numbers can be added, subtracted, multiplied and divided. 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).
A rational number is the quotient of two integers - the numerator and denominator. The denominator cannot be zero. Two rational numbers can be added, subtracted, multiplied and divided. 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).
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images