next up previous
Next: About this document ... Up: Assignment 13: Object methods Previous: Assignment 13: Object methods

Rational objects

In Homework 9, we wrote a class called Rational that implemented rational numbers as an object with two integer instance variables.

I have put a version of the solutions to that project in

http://rocky.colby.edu/cs151/code/hw13/cs151.java

In the same directory you will also find example programs called ComplexBefore and ComplexAfter, which were the examples I used in class.

1.
Pick up a copy of the Rational, import it into a CodeWarrior project, and compile and run it.

2.
Transform each of the methods in the Rational class from class methods to object methods, and make the necessary changes in main.

3.
Make a few mistakes. Try invoking class methods as if they were object methods and vice-versa. Try to get a sense for what is legal and what is not, and for the error messages that you get when you mess things up. This will be good preparation for the debugging portion of the final.

4.
Think about the pros and cons of the two method styles (class and object methods). Which is more concise (usually)? Which is a more natural way to express computation (or, maybe more fairly, what kind of computations can be expressed most naturally using each style)?


next up previous
Next: About this document ... Up: Assignment 13: Object methods Previous: Assignment 13: Object methods
Allen Downey
1999-12-16