In this exercise you're playing a role-playing game where different types of fighters can combat each other. The game has different rules for each type of fighter. We are going to focus on two specific types: Wizards and Warriors.
For a Warrior, these are the rules:
6 points of damage if the fighter they are attacking is not vulnerable.10 points of damage if the fighter they are attacking is vulnerable.For a Wizard, these are the rules:
12 points of damage if they prepared a spell in advance.3 points of damage if they did not prepare a spell in advance.Create a new class called Warrior.
This class should inherit from the existing Fighter class.
Update the Warrior class so that its toString() method describes what kind of fighter they are.
The method should return the string "Fighter is a Warrior".
Warrior warrior = new Warrior();
warrior.toString();
// => "Fighter is a Warrior"Update the Warrior class so that its isVulnerable() method always returns false.
Warrior warrior = new Warrior();
warrior.isVulnerable();
// => falseUpdate the Warrior class so that its getDamagePoints(Fighter) method calculates the damage dealt by a Warrior according to the rules above.
Warrior warrior = new Warrior();
Wizard wizard = new Wizard();
warrior.getDamagePoints(wizard);
// => 10Create another new class called Wizard.
This class should also inherit from the existing Fighter class.
Update the Wizard class so that its toString() method describes what kind of fighter they are.
The method should return the string "Fighter is a Wizard".
Wizard wizard = new Wizard();
wizard.toString();
// => "Fighter is a Wizard"Update the Wizard class to add a method called prepareSpell().
The class should remember when this method is called, and make sure that its isVulnerable() method returns false only when a spell is prepared.
Wizard wizard = new Wizard();
wizard.prepareSpell();
wizard.isVulnerable();
// => falseUpdate the Wizard class so that its getDamagePoints(Fighter) method calculates the damage dealt by a Wizard according to the rules above.
Wizard wizard = new Wizard();
Warrior warrior = new Warrior();
wizard.prepareSpell();
wizard.getDamagePoints(warrior);
// => 12In this exercise you're playing a role-playing game where different types of fighters can combat each other. The game has different rules for each type of fighter. We are going to focus on two specific types: Wizards and Warriors.
For a Warrior, these are the rules:
6 points of damage if the fighter they are attacking is not vulnerable.10 points of damage if the fighter they are attacking is vulnerable.For a Wizard, these are the rules:
12 points of damage if they prepared a spell in advance.3 points of damage if they did not prepare a spell in advance.Create a new class called Warrior.
This class should inherit from the existing Fighter class.
Update the Warrior class so that its toString() method describes what kind of fighter they are.
The method should return the string "Fighter is a Warrior".
Warrior warrior = new Warrior();
warrior.toString();
// => "Fighter is a Warrior"Update the Warrior class so that its isVulnerable() method always returns false.
Warrior warrior = new Warrior();
warrior.isVulnerable();
// => falseUpdate the Warrior class so that its getDamagePoints(Fighter) method calculates the damage dealt by a Warrior according to the rules above.
Warrior warrior = new Warrior();
Wizard wizard = new Wizard();
warrior.getDamagePoints(wizard);
// => 10Create another new class called Wizard.
This class should also inherit from the existing Fighter class.
Update the Wizard class so that its toString() method describes what kind of fighter they are.
The method should return the string "Fighter is a Wizard".
Wizard wizard = new Wizard();
wizard.toString();
// => "Fighter is a Wizard"Update the Wizard class to add a method called prepareSpell().
The class should remember when this method is called, and make sure that its isVulnerable() method returns false only when a spell is prepared.
Wizard wizard = new Wizard();
wizard.prepareSpell();
wizard.isVulnerable();
// => falseUpdate the Wizard class so that its getDamagePoints(Fighter) method calculates the damage dealt by a Wizard according to the rules above.
Wizard wizard = new Wizard();
Warrior warrior = new Warrior();
wizard.prepareSpell();
wizard.getDamagePoints(warrior);
// => 12