| Build upon our knowledge of user-defined classes, and gain experience using inheritance and polymorphism to create a class hierarchy. Inheritance will be used to consolidate code (behavior and data) shared among multiple classes at the most general level, and polymorphism will be used to treat specific objects as members of a general class. |
| This lab is to help you with homework 9. Before you start lab 9 please read instructions of homework 9 carefully. |
|
A screen saver is an application which runs on a computer when it has been idle
for some time. Usually, the screen saver draws some graphics on the screen and
animates these graphics in some way. In this homework, you will create three
classes which can be drawn by a screen saver engine.
Since the objective is to learn about using inheritance and polymorphism, the actual ScreenSaver implementation will be provided to you. You will build a screen saver that displays an animated aquarium scene like the one shown below.
Your task will be to create the classes to represent the types of animals that
will be drawn by the screen saver. The hierarchy of classes that you will
implement is shown below.
|
AquariumAnimal and Fish will be
abstract superclasses that contain fields and/or methods
that are common to their subclasses. The other three classes (Snail,
Goldfish, and Guppy) will be non-abstract classes that
will be used to construct the objects that represent the individual animals on the
screen.
We give you the basic requirements for these classes below, but it is up to you
to implement them in a correct and concise way. In particular, your
class implementations must take advantage of inheritance by
putting instance variables and methods that are common to multiple classes
in the appropriate superclass. Doing so will allow you to avoid duplicating code,
since code that is shared by multiple classes can be written once and inherited in
the subclasses. Also, your implementation of these classes must work with the driver
class Here is what you need to know in order to decide which instance variables and methods are needed, and in which class or classes they should be defined:
Here are some other suggestions/hints:
The ScreenSaver class
We are providing you with the client class
|
|
Cooperation is recommended in understanding programming concepts and system
features. But the actual solution of the assignments including all programming
must be your individual work. For example, copying without attribution any part
of someone else's program is plagiarism, even if you have modified the code.
The University takes acts of cheating and plagiarism very seriously; first time
violators are routinely suspended for a semester. |