Question: Implement and test the following classes and objects in SCALA. 1. A gladiator has a read-only name and an integer health level which is initially

Implement and test the following classes and objects in SCALA.

1. A gladiator has a read-only name and an integer health level which is initially 100 (this may not be initialized by users). Health is decremented by a damage method that takes an integer amount of damage as input and decrements health by that amount. However, health can never be negative. A gladiator has an attack method that has a gladiator opponent parameter. When called it simply prints the names of the attacker and the victim, then damages the victim by 5 points.

2. Slasher, Masher, and Crusher are traits with methods called slash, mash, and crush, respectively. Each takes a gladiator opponent parameter. When called it describes the slashing, mashing, or crushing, then decrements the opponents health by 10 points.

3. A CrusherMasher inherits from Gladiator, Crusher, and Masher. It overrides attack, calls the inherited attack, then calls the inherited crush and mash methods.

4. Create two gladiators: Optimus Prime of type CrusherMasher and Bumble Bee, a singleton object that inherits from Gladiator, Slasher, and Masher. Override its attack method so that it calls the inherited attack method then calls its inherited slash and mash.

5. Test your code as follows:

for(i <- 0 to 5) { maximus.attack(bee) bee.attack(maximus) } //> Maximus Prime is attacking Bumblebee //| Slash, slash, slashing Bumblebee //| Bumblebee's health = 95 //| Mash, mash, mashing Bumblebee //| Bumblebee's health = 90 //| Bumblebee is attacking Maximus Prime //| Crush, crush, crushing Maximus Prime //| Maximus Prime's health = 95 //| Mash, mash, mashing Maximus Prime //| Maximus Prime's health = 90

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!