Rational Numbers Practice

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Rational Numbers Practice

1. Create a class Rational


2. Create 2 constructors
- Rational()
- Rational(int numerator, int denominator)

3. Attributes of class
- int numerator, int denominator

4. Behaviour of class
- public void add(Rational r2) --> should add r2 to r1
- public void subtract(Rational r2) --> should subtract r2 fromr1
- public void print() --> should print in the format "a/b"

5. Main function
- create 2 objects: one with default constructor and one with
the Rational(r1, r2) constructor
- call r1.add(r2) and print the new value of r1
- call r1.subtract(r2) and print the new value of r1

You might also like