You are on page 1of 3

Fun Day: A Skit for the Turtles

Today, you and a classmate will create an animation using the World class and the
Turtle class in JES. The turtles are putting on a skit in which the lead turtle is chasing
some of the other actor turtles and being chased by a different set of actor turtles. They
have hired you to create the theme for their skit, design the costumes, and choreograph
the chases.

Learning Objectives
1. Write classes and subclass definitions complete with methods and attributes.
2. Use inheritance, encapsulation, and polymorphism.
3. Write a main event loop which calls methods for a list of objects.

Design First, decide together what your skit will be about. Here is a handy worksheet:

A herd of elephants is being chased by a mouse, while at the same time the mouse is
being followed by a group of birds that wish to eat the mouse.

Lead turtle represents: Mouse

Size, color, and initial placement:

Small red oval that spawns in randomly.

Follows the Elephants

Chasers represent: Birds

Size, color, and initial placement:

Small purple ovals that spawn in randomly.

The Birds will follow the Mouse.
The Chased represent: Elephants

Size, color, and initial placement:

Large blue ovals that spawn near the center of the world.

Elephants move in a pre-mapped loop.

Coding Start with the shell for the mice and elephants animation.

Step 1: Two kinds of animals. Pick two of your three kinds of animals. Rename the
mice class and rename the elephants class. Rename the constants for the mice and
elephants so that they represent these two kinds of animals. Change the main function
so that it populates the stage with several of each of these two kinds of animals. Run
your animation to see what is happening, and fine-tune it before adding the third kind
of animal.

Step 2: Add in the third kind. Create the third kind of Animal by creating a new class
and writing its __init__ and move methods. Be sure to initialize constants for your new
kind of animal.

Change the main function so that it populates the stage with several of each of the three
kinds of animal in your animation. Do you need to change the event loop that causes
the turtles to move?

Testing Run your animation several times to make sure it is doing what you want it to

Submitting your work

Post your final program on the discussion board for today and indicate who your team
members are. Use a creative title. We will play all of the animations on Friday.

Individually complete the analysis detailed below.

Analysis of program
1. What are the classes that you define in your code? Mouse, Elephant, Bird, and
2. Give an example of an instance that is created in your code. What line of code
creates that instance? A particular bird is an instance.

3. Give an example of each of the following in your animation:

a. an object
Any individual mouse.
b. a method
The movement directions for the animals.
c. an attribute
Colors and width/height for the animals.
d. a subclass
e. a superclass
f. a constructor
The initializer at the beginning that defines the world.
4. Give an example in your animation code of each of the three main concepts in
object oriented programming:
a. polymorphism
While both the Mice and Elephant classes are subclasses of Animal,
elephants move in a pre-defined path whereas mice follow another object.
b. encapsulation
The world that all of this takes place in is self-contained and all actions
take place inside of it.
c. Inheritance
Subclass “bird” inherits the traits of the superclass “animal.”