Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Write the Java code to declare a new class Bee which is a subclass of Insect. The noise made by a Bee is Buzz.

2. Write the Java code to declare a new class Bee which is a subclass of Insect. The noise made by a Bee is "Buzz".

3. Write the Java code to declare a new abstract class Amphibian that implements the MakesNoise interface.

4. Write the Java code to declare a new class Frog which is a subclass of Amphibian. The noise made by a Frog is "Ribbet".

5 Modify the run() method of Main and add some Bees and Frogs to critters. Build your program and verify that it works correctly. Include all of your .java source code files

---------------

Heres what I have so far, and can't seem to get any further.....

-------------------

import java.util.ArrayList;

public interface MakeNoise {

public void MakeNoise();

void makeSound();

}

public abstract class Mammal implements MakeNoise{

}

public abstract class Insect implements MakeNoise{

}

public abstract class Amphibian implements MakeNoise{

}

public class Dog extends Mammal{

@Override

public void makeNoise() {

System.out.println("Bark");

}

}

public class Cat extends Mammal{

@Override

public void makeNoise(){

System.out.println("Meow");

}

}

public class Cricket extends Insect{

@Override

public void makeNoise(){

System.out.println("Chirp");

}

}

public class Bee extends Insect{

@Override

public void makeNoise(){

System.out.println("Buzz");

}

}

public class Frog extends Amphibian{

@Override

public void makeNoise(){

System.out.println("Ribbet");

}

}

public class Main{

public static void main(String[] args)

{new Main().run();}

public void run(){

ArrayList critters = new ArrayList<>();

critters.add(new Dog());

critters.add(new Cat());

critters.add(new Cricket());

critters.add(new Cat());

critters.add(new Cricket());

critters.add(new Bee());

critters.add(new Bee());

critters.add(new Frog());

beNoisy(critters);

}

public void beNoisy(ArrayList pCritters) {

for(MakeNoise critter : pCritters) {

critter.makeSound();

}

}

}

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago