Course Home | Assignments | Class Photo | Computing Resources | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Spring 2010

Dept. of Math & Computer Science

Programming Assignment 09

Animal

Due: 11:59pm, Sunday 18 April 2010


Contents:


Overview

In an earlier assignment, Artist, you created an animation which included several animals. At that time, you relied on the use of the class, Layer, to manipulate your animal as a single coherent unit, rather than as a scattered collection of individual shapes. We saw several advantages in that representation of an animal, such as being able to easily move the animal in the scene.

That use of the class Layer was a step in the right direction, but this time we would like to go a step further, having you create and document a new class which represents your specific animal.

Newly Introduced Techniques

Reading: Chapter 9.4, 9.6

Collaboration Policy

For this assignment you must work individually in regard to the design and implementation of your project.

Please make sure you adhere to the policies on academic integrity in this regard.


Revisiting Our Earlier Work

For the sake of discussion, let's suppose that my original Artist submission has generated an animation which included several monkeys. Presumably my code included some 30-40 lines of code specifically for modeling the monkey. I probably instantiated various shapes to represent the arms, legs and tail of the monkey, as well as instantiating a new Layer to represent the monkey as a whole. Then the body parts were added to the layer, and the layer was added to the canvas.

Suppose that I were proud of my representation of a monkey and that I wanted to add more monkeys into my scene, or better yet, I wanted to allow other people to conveniently add my monkeys into their own animations. I might accomplish this by simply making the 30-40 lines of code which I had used available to others, verbatim, for inclusion in other places. But a much better design, in the spirit of object-oriented programming, would be to define a new class, say Monkey containing the necessary code. Then, others could use this new class with minimal effort, just as they had used the more primitive shapes. For example, an artist might simply specify:

    chimp = Monkey()
    chimp.move(80,120)
    chimp.scratch()
    paper.add(chimp)

This is our goal. Of course, there is no reason to reinvent the wheel; we do not wish to create our new class entirely from scratch. We have already seen that the concept of a Layer is a great model for representing a Monkey, and so we will use inheritance to define a Monkey as a subclass of Layer. Therefore, we might start out our class definition using syntax such as:

from cs1graphics import *

class Monkey(Layer):
    ...

In this way, any object from class Monkey inherits all of the instance variables and methods associated with the class Layer, such as move(), draw(), setDepth() and so on. Of course, if we do not add any additional code to the class definition for Monkey, then our class will be identical to that of a Layer. Presumably, new instance variables and behaviors may be added, and existing behaviors might be specialized.


Requirements

There are three distinct directions of work which are required for your submission.

  1. Create a new class, representing a type of animal.

    In this assignment description, we have been using the discussion of a class Monkey purely for example. Your project should involve the development of a new class to represent your own choice of animal, most likely an animal used in your original Artist project (though you are free to change your mind).

    Please adhere strictly to the following minimum requirements for the development of such a class:

  2. Properly document all aspects of your newly defined animal class.

    For someone else to know how to use your class, you must provide sufficient documentation. For this, we would like you to use docstrings, as described in earlier work. Specifically, please ensure that:

  3. Provide a Unit Test which demonstrates the use of your class.

    Here, the goal is to show how your class could be used by another. So provide a construct of the form:

    if __name__ == '__main__':
    
    as the final thing in your source code, where the body of the construct demonstrates the use of your class.

    Your animation for this assignment does not need to correspond to the precise animation you created in the original Artist assignment. However, we would like your new animation to satisfy the following requirements:


Advice About Coordinate System

Please keep in mind that the default reference point for a Layer is at (0,0) of the layer's coordinate system. Therefore, this is the default reference point for your shape. Please think carefully about designing your geometry relative to that point. Is there a natural point in your animal's geometry to serve as a reference point? When a user calls a method such as moveTo(100,100) where will this cause your animal to go? Also, the reference point is important for the inherited scale and rotate commands.


Submitting Your Assignment

You should create a new file, appropriately names, which contains all of your own code. This file must be submitted electronically.

You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments.

Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.


Extra Credit

I'll know it when I see it.


Michael Goldwasser
Last modified: Monday, 29 March 2010