Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

What is your least favorite U.S. dialect? Why?

Answered: 1 week ago

Question

6. Vanguard

Answered: 1 week ago