Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a JAVA program that will: Use inheritance Operates with polymorphism Use a random number generator to determine what enemy type will be created and

Create a JAVA program that will:

Use inheritance

Operates with polymorphism

Use a random number generator to determine what enemy type will be created and stored in an ArrayList.

For this program, you will create a general abstract Enemy class with the following fields:

weight (an integer)

height (an integer)

The Enemy class must also have the following methods:

Getters for both the weight and height

Setters for both the weight and height

A constructor that takes the weight and the height

An abstract method, attack, that (when implemented) will simply print out (using System.out methods) the specific attack of the subclass type.

In addition to the Enemy class, you should have four different concrete (non-abstract) classes that extend the Enemy class:

Daemon

o Weight should be generated randomly between 20 and 40

o Height should be generated randomly between 100 and 300

o The attack method should print Blahh!

Goon

o Weight should be 0

o Height should be generated randomly between 30 and 75

o The attack method should print Waaaahhh!

Wolf

o Weight should be generated randomly between 30 and 88

o Height should be generated randomly between 100 and 150

o The attack method should print Hayahh!

Monster

o Weight should be generated randomly between 2000 and 3500

o Height should be generated randomly between 220 and 400

o The attack method should print Arrrr!

The program should create an ArrayList capable of holding any kind of Enemy that is listed. It must be able to generate 100 different enemies using random number generators (RNGs) to select an enemy, and be able to set their specifications (e.g., weight and height) when necessary.

If the RNG returns a 1, then create a Daemon and add it to the ArrayList. If the RNG returns a 2, create a Goon. If it returns a 3, create an Wolf, and if it returns a 4, create a Monster.

According to that, the number used from the RNG should ultimately fall between 1 and 4 (inclusive) which can be scaled appropriatly by shifting of the values returned by the RNG

Add each of the 100 enemies to the ArrayList, and then loop through the array list and print out the attacks from each of the enemies in the array list.

Example output:

Waaaahhh!

Arrrr!

Waaaahhh!

Waaaahhh!

Arrrr!

Hayahh!

Blahh!

Hayahh!

Hayahh!

etc......

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 Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions