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
docs: adding subjects for quest 4 of the java piscine (#2061)
1 year ago
..
README.md docs: adding subjects for quest 4 of the java piscine (#2061) 1 year ago

README.md

AdventureMonster

Instructions

Create a new class Monster in a new file Monster.java.

This class inherits from Character.

It has one constructor, with the same 2 parameters (the name and the maxHealth) as Character.

You need to overwrite the toString method with the following format :

  • if the monster is still alive : <name> is a monster with <currentHealth> HP.
  • Otherwise : <name> is a monster and is dead.

Usage

Here is a possible ExerciseRunner.java to test your function :

public class ExerciseRunner {

    public static void main(String[] args) {
        Character aragorn = new Character("Aragorn", 20);
        Monster slime = new Monster("Slime", 15);

        System.out.println(Character.printStatus());

        Character winner = Character.fight(aragorn, slime);

        System.out.println(Character.printStatus());
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner 
------------------------------------------
Characters currently fighting : 
 - Aragorn : 20/20
 - Slime is a monster with 15 HP
------------------------------------------
------------------------------------------
Characters currently fighting : 
 - Aragorn : 11/20
 - Slime is a monster and is dead
------------------------------------------
$ 

Notions

Inheritance