AP Computer Science :: Projects :: Old MacDonald's Farm
Problem
In this project, you will be creating Old MacDonald's Farm using inheritance. Every animal on the farm has a type (such as cow or pig) and makes a sound (such as moo or oink). This project was adapted from a project originally conceived by Roger Frank of Ponderosa High School in Parker Colorado. You can watch the video below if you've never heard the song "Old MacDonald" before:
Old MacDonald's Farm contains the following interface:
public interface Animal { public String getSound(); public String getType(); }
Instructions
Using the interface detailed above, create Old MacDonald's Farm with the following properties:
- Create classes for Cow, Chick, and Pig, as well as another animal of your choice that implement the interface.
- Create a Farm class that creates animal of all four types and outputs their sound in the form "The TYPE goes SOUND."
- Modify the Chick class so it can say two sounds. Each sound should have an equal probability of being made.
- Create a new class called NamedCow that works exactly like a cow, but also has a name that is set at the beginning and can be found using a getName() accessor.