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.
Abdelilah Khossan
78e9c1846c
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
AdventureTemplar
Instructions
We will now implement our second interface through a new class : Templar
in a file named Templar.java
.
This class implements Healer
and Tank
interfaces and inherits from Character
.
It has two new attributes :
- a non modifiable integer
healCapacity
, - a non modifiable integer
shield
.
It has a constructor with four parameters :
name
,maxHealth
,healCapacity
,shield
From the Healer
interface :
getHealCapacity
returns the propertyhealCapacity
heal
addshealCapacity
to the currentHealth of theCharacter
in parameter. Beware thatcurrentHealth
can't be greater themaxHealth
.
From Tank
interface :
getShield
returns the propertyshield
.
You will override toString
method with the following format : <name> is a strong Templar with <currentHealth> HP. It can heal <healCapacity> HP and has a shield of <shield>.
If its currentHeal
is equal to 0, the format is <name> has been beaten, even with its <shield> shield. 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) {
Templar alistair = new Templar("Alistair", 20, 5, 4);
Templar roderick = new Templar("Roderick", 10, 3, 2);
Character.fight(alistair, roderick);
alistair.heal(alistair);
System.out.println(Character.printStatus());
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
------------------------------------------
Characters currently fighting :
- Alistair is a strong Templar with 16 HP. It can heal 5 HP and has a shield of 4.
- Roderick has been beaten, even with its 2 shield. So bad, it could heal 3 HP.
------------------------------------------
$