[Solved] CS2124-Homework 3-Data Hiding Encapsulation Delegation

$25

File Name: CS2124_Homework_3_Data_Hiding_Encapsulation_Delegation.zip
File Size: 508.68 KB

SKU: [Solved] CS2124-Homework 3-Data Hiding Encapsulation Delegation Category: Tag:
5/5 - (1 vote)

Homework 3Problem:We will expand our Warrior a little. Each Warrior will have a weapon. He is born with it, i.e. the weapon is created together with the warrior. It can only be accessed by him. It provides him with his strength. In battle, weapons lose their edge and weaken. When a Warriors weapon loses all of its strength, the Warrior himself dies.

ImplementationWhat are the types of things in the problem? We will need a class for each type.What do the things / types do? These behaviors should be represented as methods.Weapons have both a name and a strength. The weapon is created together with the Warrior and cannot be accessed by anyone else.The input file needs to change a little. When a Warrior is created, instead of simply specifying his name and strength, the command will specify the Warriors name as well as his Weapons name and its strength.The Status report will also be modified to show the name of the Warriors Weapon.No one can access a warriors weapon accept the warrior himself. But the weapon is what actually holds the warriors strength. How does this effect the programming? Any time the code needs to know or change the warriors strength, the warrior then asks the weapon what the strength is or tells the weapon that the strength needs to be changed. This represents the idea of delegation. We will see this concept frequently, where one object requests that another object do some task.InputOur sample input file might now look like:

Warrior Jim Glamdring 42Warrior Lancelot Naegling 15Warrior Arthur Excalibur 15Warrior Torvalds Narsil 20Warrior Gates Orcrist 8StatusBattle Arthur LancelotBattle Jim LancelotBattle Torvalds GatesBattle Gates LancelotStatusOutputThe corresponding output would be:

There are: 5 warriorsWarrior: Jim, weapon: Glamdring, 42Warrior: Lancelot, weapon: Naegling, 15Warrior: Arthur, weapon: Excalibur, 15Warrior: Torvalds, weapon: Narsil, 20Warrior: Gates, weapon: Orcrist, 8Arthur battles LancelotMutual Annihilation: Arthur and Lancelot die at each others handsJim battles LancelotHes dead, JimTorvalds battles GatesTorvalds defeats GatesGates battles LancelotOh, NO! Theyre both dead! Yuck!There are: 5 warriorsWarrior: Jim, weapon: Glamdring, 42Warrior: Lancelot, weapon: Naegling, 0Warrior: Arthur, weapon: Excalibur, 0Warrior: Torvalds, weapon: Narsil, 12Warrior: Gates, weapon: Orcrist, 0

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2124-Homework 3-Data Hiding Encapsulation Delegation[Solved] CS2124-Homework 3-Data Hiding Encapsulation Delegation
$25