Answered step by step
Verified Expert Solution
Link Copied!

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 non-player characters and processes any attacks. Initially, the
list _npcs is empty. Non-player 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 non-player 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 non-player 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 non-player characters. There are
two classes of non-player 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 15 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:
1. Implement the program described above. You must write code for all classes, methods,
fields, and constructors.
2. Write a Main method to test your implementation:
a. Create a Stadium object.
b. Tell the Stadium object to Attack with 10 damage.
c. Tell the Stadium object to AttackAll with 5 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 8 damage.
g. Tell the Stadium object to Attack with 10 damage.
h. Tell the Stadium object to AttackAll with 9 damage. Explain four fundamental principles of object-oriented programming. For each principle,
refer to some task that you have completed for COS20007 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

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago