Saturday, July 27, 2013

Last Program -- The Menagerie

This program is MUCH easier than many of the programs of the summer.  There will be a lot of classes involved (and one interface), but each of them is simple as pie.  Here is my best attempt at a UML diagram of all but the driver class:

The methods called roam, eat, vocalize, and play simply print to the output with System.out.println.

My Menagerie class didn't contain anything but a main.  It created an ArrayList (although an array would work fine) and then created a Dog, a Cat, a Wolf, and a Tiger.  It added each of those to the ArrayList.  Then it traversed the list and, for each animal, it printed the animal's name and age using the toString, then called roam, eat, vocalize, and play (calling play only if the animal was a pet).

That's it!  Write if you have questions.

No comments:

Post a Comment