CS 214 Project 10: Class Hierarchies


This week's project is to extend your Java, Ada, and Ruby class hierarchies with some new classes:

which are described further below. Note that we will not be using Clojure in this project, because as a functional language, it really isn't intended to support object-oriented programming and class hierarchies.

Class Hierarchy Exercise

As in the lab exercise, each kind of bird should respond appropriately to name() and call() messages. However, where owls, geese, and ducks are flying birds, penguins, ostriches, and kiwis are non-flying birds, so you are to modify things such that (for example) C++ code like this:

   Bird * birdPtr0 = new Duck("Donald");
   Bird * birdPtr1 = new Penguin("Peter);
   Bird * birdPtr2 = new Goose("Mother");
   Bird * birdPtr3 = new Ostrich("Orville");
   ...
   birdPtr0->print();
   birdPtr1->print();
   birdPtr2->print();
   birdPtr3->print();
   ...
will produce output like this:
   Donald Duck just flew past and said, "Quack"
   Peter Penguin just walked past and said, "Huh-huh-huh-huuuuh"
   Mother Goose just flew past and said, "Honk"
   Orville Ostrich just walked past and said, "Snork"
   ...
(You can make up your own call for a kiwi.)

To make all of this happen with a minimal amount of code, you are to rewrite the print() method in class Bird to be something like the following:

   inline void Bird::print(ostream & out) const {
      out <<name() 
           <<' ' 
          << className() 
          << " just "
          << movement()
          << " and said " 
          << call();
   } 
In order for this to work, you should
  1. add an abstract movement() message to class Bird;
  2. define two new subclasses of Bird named FlyingBird and WalkingBird;
  3. have each of these subclasses define movement() appropriately;
  4. revise the definitions of classes Owl, Duck, and Goose to make them subclasses of FlyingBird; and
  5. define classes Penguin, Ostrich, and Kiwi as subclasses of WalkingBird.
You will need to research how to go about creating an abstract method in each language.

The resulting class hierarchy should look something like this:

an extended bird hierarchy

Testing. In each language, modify the birds program so that it demonstrates that your class hierarchy works correctly. Make certain that it creates instances of all six 'leaf' classes in the hierarchy.

Turn in. Using an approach like what we did in the lab, make a single script file named proj10-results, in which you list all of the files for each program, show that it builds without any syntax errors or warnings, and show some executions that demonstrate its correctness. Then submit your project by copying that single file into your personal folder in /home/cs/214/current/:

   cp proj10-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name. The grader will access and grade your project results from there, using the criteria from this grade sheet.


Calvin > CS > 214 > Projects > 10


This page maintained by Joel Adams.