mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zanninso
378852698e
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
AdventureSorcerer
Instructions
We will now implement our first interface through a new class : Sorcerer
in a file named Sorcerer.java
.
This class implements the Healer
interface and inherits from Character
. It has a new attribute : an integer healCapacity
.
It has a constructor with three parameters :
name
,maxHealth
healCapacity
From the Healer
interface :
getHealCapacity
returns the propertyhealCapacity
heal
addhealCapacity
to the currentHealth of theCharacter
in parameter. Beware that thecurrentHealth
can't be greater themaxHealth
. You may need to change the accessibility of thecurrentHealth
param in theCharacter
to be able to update the value.
You will override the toString
method with the following format : <name> is a sorcerer with <currentHealth> HP. It can heal <healCapacity> HP.
If it's currentHeal
is equal to 0, the format is <name> is a dead sorcerer. So bad, it could heal <healCapacity> HP.
Usage
Here is a possible ExerciseRunner.java to test your function :
public class ExerciseRunner {
public static void main(String[] args) {
Sorcerer gandalf = new Sorcerer("Gandalf", 20, 5);
Character frodon = new Character("Frodon", 20);
Sorcerer saroumane = new Sorcerer("saroumane", 10, 3);
Character.fight(frodon, saroumane);
gandalf.heal(frodon);
System.out.println(Character.printStatus());
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
------------------------------------------
Characters currently fighting :
- Gandalf is a sorcerer with 20 HP. It can heal 5 HP.
- Frodon : 16/20
- Saroumane is a dead sorcerer. So bad, it could heal 3 HP.
------------------------------------------
$