2008 September 24 / jjddaavviiss@@ccaarrlleettoonn..eedduu
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.
Download these files to your computer. Put them all in a single folder.
Fish
Class
Write a class named Fish
. It should have the following methods.
swim()
should take in one argument:
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.)
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
.
Fish
's constructor takes, and a sixth argument: the color of the stripe. It should call Fish
's constructor, then add the stripe and draw the fish with the stripe.
fancySwim()
takes in a single argument — the number of pixels to swim — but it causes the fancy fish to swim up by that amount, then forward by that amount, then down by that amount. You should call Fish
's swim()
method to accomplish the forward swimming part.
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?
Your file aquarium.py will be graded on these points:
FancyFish
make proper use of its superclass Fish
? (3 points)
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.