2008 September 24 / jjddaavviiss@@ccaarrlleettoonn..eedduu

Assignment 2

Carleton College CS 201, Fall 2008, Prof. Joshua R. Davis

The goal of this assignment is to practice writing Python code — in particular, writing subclasses and using a graphics library. By the end, you will have a functioning virtual aquarium.

0. Start Your Engines

Download these files to your computer. Put them all in a single folder.

Open a Terminal window and navigate to that folder. Open the aquarium.py file in Smultron. Notice that I've typed "!!" in four places. It's not because I'm excited (although I am); those "!!" indicate where you are going to make changes. The first one is where you type your name; do that now.

1. Write The Fish Class

Write a class named Fish. It should have the following methods.

2. Test The Fish Class

Modify main() to instantiate three to five fish and make them swim from their starting location to the edge of the screen. (If they swim off the screen, that's okay.)

3. Write The FancyFish Class

Write a class named FancyFish that is a subclass of Fish. Fancy fish are fancy in two ways: they have stripes, and they swim in a complicated manner. Here are the methods for FancyFish.

4. Test Both Kinds Of Fish

Modify main() so that it instantiates three to five fish of each kind and makes them swim. If they swim off the screen, that's okay. On the other hand, if you have time, then perhaps you can improve this behavior?

5. Hand In Your Work

Your file aquarium.py will be graded on these points:

Here's how you submit aquarium.py electronically. In the Terminal, make sure that you are in the directory where your aquarium.py file is. Then type

hsp aquarium.py cs201-00-f08

This command launches the CS department's homework submission program. It will ask for your usual Carleton password. If you have problems, contact Mike Tie in CMC 305.