Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started