Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Class Stadium maintains a list of non - player characters and processes any attacks. Initially, the list _ npcs is empty. Non - player characters
Class Stadium maintains a list of nonplayer characters and processes any attacks. Initially, the
list npcs is empty. Nonplayer characters can be added by using the Add method of class
Stadium.
When you tell an object of class Stadium to Attack, one of two things will happen:
If the list of nonplayer characters is not empty, then
o The message Bring it on is sent to the console.
o The first character in the list is told to GetHit using the specified amount of dam
age.
Else
o The message Not very effective... is sent to the console.
When you tell an object of class Stadium to AttackAll, one of two things will happen:
If the list of nonplayer characters is not empty, then
o The message Charge is sent to the console.
o Every character in npcs is told to GetHit using the specified amount of damage.
Else
o The message Why is sent to the console.
The abstract class Character defines the common features of nonplayer characters. There are
two classes of nonplayer characters: Mortal and Immortal. Class Mortal is a kind of Character. Objects of class Mortal also define a field health. When
creating new objects of class Mortal, use as initial value for health. When an object of class
Mortal is told to GetHit, then one of two thing will happen:
If the Mortals health is greater than zero, then
o The message Odysseus: Ow is sent to the console, where Odysseus is the
name of the Mortal.
o The field health is reduced by the value damage.
Else
o The message Odysseus: You already got me is sent to the console, where
Odysseus is the name of the Mortal.
Class Immortal is a kind of Character. When an object of class Immortal is told to GetHit, then
The message Zeus: Ha Nice try. is sent to the console, where Zeus is the name of
the Immortal.
Your task is to:
Implement the program described above. You must write code for all classes, methods,
fields, and constructors.
Write a Main method to test your implementation:
a Create a Stadium object.
b Tell the Stadium object to Attack with damage.
c Tell the Stadium object to AttackAll with damage.
d Add three Mortal objects to the Stadium object.
e Add one Immortal object to the Stadium object.
f Tell the Stadium object to AttackAll with damage.
g Tell the Stadium object to Attack with damage.
h Tell the Stadium object to AttackAll with damage. Explain four fundamental principles of objectoriented programming. For each principle,
refer to some task that you have completed for COS and elaborate how the princi
ple is used to achieve the objective of the task.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started