// Print the Old MacDonald song // Beth Katz - April 2009 public class MacClass { public static void main(String[] args) { // one animal Animal bossy = new Animal("bossy cow", "MOOOO"); printSong(bossy.name( ), bossy.sound( )); // many animals Animal[ ] animal = new Animal[5]; animal[0] = new Animal("cow", "moo"); animal[1] = new Animal("dog", "woof"); animal[2] = new Animal("horse", "neigh"); animal[3] = new Animal("pig", "oink"); animal[4] = new Animal("hen", "cluck"); for (int i = 0; i < animal.length; i++) { printSong(animal[i].name( ), animal[i].sound( )); } } // print the song with the given animal and sound public static void printSong(String animal, String sound) { System.out.println("Old MacDonald had a farm"); eieio( ); System.out.println("and on his farm, he had a " + animal); eieio( ); System.out.println("with a " + sound + " " + sound + " here"); System.out.println("and a " + sound + " " + sound + " there"); System.out.println("here a " + sound + " there a " + sound); System.out.println("everywhere a " + sound + " " + sound); System.out.println("Old MacDonald had a farm"); eieio( ); System.out.println( ); } // print the special letters public static void eieio( ) { System.out.println("E-I-E-I-O"); } }