next up previous
Next: Using objects as return Up: Assignment 8: Strings, series, Previous: Captain Crunch

Using objects as parameters

1.
Start with a clean copy of the Snowperson assignment. You can use my solutions if you want or you can use your own.

http://rocky.colby.edu/cs151/solutions/hw4/

If you use your solution, you might want to take a minute to review it, make sure you remember how it works, and clean it up a little.

2.
Add a few lines of code to the program and experiment with Rectangle and Point objects a bit. Try out one or two of the examples from the book or Quiz 12. Try creating an object variable (but no object) and then access one of the instance variables. What happens? Look at the output from the exception handler and see if you can find the line of the program that caused the error.

3.
Modify the Snowperson code so that every method that receives a bounding box as an argument gets a single Rectangle object instead of four integers. For example, the declaration of paintSnowperson would look like

    public void paintSnowperson (Graphics g, Rectangle bb)

4.
Please turn in a paragraph that compares the two versions, discussing things like readability, debuggability, code length and encapsulation.

In the Java library, they had the option of using Rectangles to pass parameters to methods like drawRect and drawOval, but they chose to pass four integers instead. In fact, there are only a couple of methods in the whole Java library that use Rectangles at all. What do you think of this decision? Would you prefer a version of drawOval that takes a single Rectangle as an argument? What if you could have both?


next up previous
Next: Using objects as return Up: Assignment 8: Strings, series, Previous: Captain Crunch
Allen B. Downey
1999-10-25