Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

How are values illustrated in the case?

Answered: 1 week ago

Question

Describe S. Truett Cathys self-concept and self-efficacy.

Answered: 1 week ago