Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started