CJCoding With Joseph
15free / daySign inCreate account

A GameCharacter class is provided. Its attack() returns 1, the damage of a character with no special skill. Write two subclasses that each store one extra number and override attack() to use it.

Requirements: 1. Warrior extends GameCharacter. Its constructor takes a String name and an int strength. attack() returns strength * 2. 2. Mage extends GameCharacter. Its constructor takes a String name and an int mana. attack() returns mana + 5. 3. Each constructor passes name to the GameCharacter constructor with super(name) and stores its own number in a private field. 4. Keep Warrior as the public class. Mage stays without the word public, because a Java file may have only one public class.

Do not change the GameCharacter class. The tests put both kinds into a GameCharacter[] array and call attack() on each element.

Do NOT write a main method.

Expected output

Brak hits for 14
Zia hits for 17

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
InheritanceClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.