Old MacDonald Had A Farm.
From Huben's Wiki
Line 6: | Line 6: | ||
into a new folder, and then load them into DrJava. | into a new folder, and then load them into DrJava. | ||
− | Don't look at Animal.java. Just look at TestAnimal.java. | + | Don't look at Animal.java or change anything in it. Just look at TestAnimal.java. |
The instructions are in TestAnimal.java: | The instructions are in TestAnimal.java: | ||
* You will need a class for each type of animal. You should then be able to compile and run. | * You will need a class for each type of animal. You should then be able to compile and run. | ||
− | * | + | * Make a constructor for each animal class, and call setNoise() in the constructor. Cow() should have setNoise("moo"); |
− | * You will need some classes for grouping animals together, and to | + | * You will need some classes for grouping animals together. For example, Duck and Chicken will extend a grouping class because they use the same methods. |
− | + | ** Make a diagram of the hierarchy of Animal, the grouping classes, and your farm animals. | |
+ | ** Create the grouping classes. | ||
+ | ** Fix the classes of each type of animal to extend from the grouping classes. | ||
+ | * Override methods eats(), babyfood(), and coat() from the parent classes as high up in the hierarchy as you can. | ||
When you are successful, the program will inform you. At that point, you can uncomment the "Animal.song();" line, and you should get a correct rendition of the song. | When you are successful, the program will inform you. At that point, you can uncomment the "Animal.song();" line, and you should get a correct rendition of the song. |