Next: Another modifier
Up: Assignment 9: Rational Numbers
Previous: Modifers
- 1.
- Write a method called toDouble that converts the rational
number to a double (floating-point number) and returns the result.
This method is a pure operator; it does not modify the object.
As always, test the new method.
- 2.
- Write a method called commonDivisor that finds the greatest
common divisor of the numerator and the denominator. Appendix A
provides an algorithm for finding the GCD. Remember that
commonDivisor is an operator; it should not modify the instance
variables of the object on which it is invoked.
Allen B. Downey
4/8/1998