Question: 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

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!