Question: Using the following code answer the question below: public interface Animal { void makeSound(); } public class Cow implements Animal { @Override public void makeSound()

Using the following code answer the question below:

public interface Animal { void makeSound(); } 
public class Cow implements Animal { @Override public void makeSound() { System.out.println("cow is saying moo"); } } 
import java.util.Random; public class Chicken implements Animal{ @Override public void makeSound() { Random random = new Random(); if(random.nextInt(2) == 0) { System.out.println("chicken is saying bawk!"); } else { System.out.println("chicken is saying cluck!"); } } } 
public class AnimalMain { public static void main(String[] args) { Animal a1 = new Cow(); Animal a2 = new Chicken(); a1.makeSound(); a2.makeSound(); a2.makeSound(); a2.makeSound(); a2.makeSound(); } }  Write a class for a Farm. The Farm contains a list of animals. Add an addAnimal method that will take in any animal and add it to the list. Also write a method that will sing Old MacDonald based on the animals in the list. Old MacDonald had a farm. E-I-E-I-O! And on that farm he had a . E-IE-I-O! With a   here and a  there Old MacDonald had a farm. E-I-E-I-O! 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!