Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this section? Am I writing one class under a java project? Or is it several classes under the same project?

Can someone help me with this section?

Am I writing one class under a java project? Or is it several classes under the same project?

4.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". 4.3 Write the Java code to declare a new abstract class Amphibian that implements the MakesNoise interface. 4.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". 4.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 in the zip archive that you submit for grading.

I have some things written out but the program does not run. Help please!

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("Barks"); } }

public class Cat extends Mammal {

@Override public void makeNoise() { System.out.println("Meows"); } }

public class Cricket extends Insect {

@Override public void makeNoise() { System.out.println("Chirps"); } }

public class Bee extends Insect {

@Override public void makeNoise() { System.out.println("Buzzes"); } }

public class Frog extends Amphibian {

@Override public void makeNoise() { System.out.println("Ribbets"); } }

public class Main {

public static void main(String[] args) { new Main().run(); }

public void run() { ArrayList creatures = new ArrayList<>(); creatures.add(new Dog()); creatures.add(new Cat()); creatures.add(new Cricket()); creatures.add(new Bee()); creatures.add(new Frog()); beNoisy(creatures); }

public void beNoisy(ArrayList pCreatures) { for (MakeNoise creatures : pCreatures) { creatures.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

More Books

Students also viewed these Databases questions

Question

2. DO change any clerical or calculation errors.

Answered: 1 week ago

Question

Guidelines for Informative Speeches?

Answered: 1 week ago