Question: Scenario You need to create a software class that represents a warrior in a game program. The warrior with have a health score (0

Scenario You need to create a software class that represents a warrior

Scenario You need to create a software class that represents a warrior in a game program. The warrior with have a health score (0 to 100), a strength score (1 to 5) and an intelligence score (1 to 5). The warrior will be used in battles and can take hits that will decrease health. The warrior is dead if his health score is 0. Requirements The warrior class should have these private fields: health, name, strength and intelligence. Create a constructor that takes no arguments. Default the warriors name to "unknown", health to 100, strength to 3, and intelligence to 3. Create a constructor that takes warrior name, strength and intelligence. Create a toString() method that returns a string formatted like this (example): Warrior health is: The angle brackets would be replaced with appropriate value. Create a method called isAlive() that returns true if the warrior is alive. Create a method called takeHit(). Generate a random number between 0 and 50. Decrease the warrior's health by this amount. Do not let health go below 0. Create a warrior driver class that does this: Asks for warrior's name. Creates the warrior (you can decide what the strength and intelligence should be). Repeatedly call make the warrior take a hit until the warrior is dead. The output should be similar to this (choose your own warrior name!): Warrior name? Troll King Troll King is hit! Warrior Troll Kinghealth is: 89 Troll King is hit! Warrior Troll Kinghealth is: 78 Troll King is hit!

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 Programming Questions!