summaryrefslogtreecommitdiff
path: root/graphs/java/creatureInterface
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/java/creatureInterface')
-rw-r--r--graphs/java/creatureInterface/.gitignore38
-rw-r--r--graphs/java/creatureInterface/pom.xml134
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/BaseHuman.java51
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Creature.java28
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Dragon.java74
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Fish.java27
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/FlyingInterface.java12
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Human.java8
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mage.java59
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/MagicalInterface.java56
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mermaid.java110
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpeakableInterface.java47
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Spell.java48
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpellType.java11
-rw-r--r--graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SwimmingInterface.java25
15 files changed, 728 insertions, 0 deletions
diff --git a/graphs/java/creatureInterface/.gitignore b/graphs/java/creatureInterface/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/graphs/java/creatureInterface/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store \ No newline at end of file
diff --git a/graphs/java/creatureInterface/pom.xml b/graphs/java/creatureInterface/pom.xml
new file mode 100644
index 0000000..1272b4c
--- /dev/null
+++ b/graphs/java/creatureInterface/pom.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.epita.assistants</groupId>
+ <artifactId>creatureInterface</artifactId>
+ <version>1.0</version>
+
+
+ <properties>
+ <versions.java>21</versions.java>
+ <versions.junit>5.9.1</versions.junit>
+ <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin>
+ <versions.maven-surefire-plugin>2.22.2</versions.maven-surefire-plugin>
+ <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin>
+ <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${versions.junit}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-registry</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.9.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${versions.maven-compiler-plugin}</version>
+ <configuration>
+ <source>${versions.java}</source>
+ <target>${versions.java}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>${versions.maven-install-plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ <configuration>
+ <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/BaseHuman.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/BaseHuman.java
new file mode 100644
index 0000000..308fde9
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/BaseHuman.java
@@ -0,0 +1,51 @@
+package fr.epita.assistants.creatureInterface;
+
+public abstract class BaseHuman extends Creature implements SpeakableInterface, SwimmingInterface{
+ /**
+ * Constructor for the Creature class.
+ *
+ * @param name The name of the creature
+ */
+ boolean inWater;
+ BaseHuman(String name) {
+ super(name);
+ inWater = false;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void hello() {
+ System.out.println("Hello, my name is " + this.name + " and I'm a " + this.getClass().getSimpleName() + ".");
+ }
+
+ @Override
+ public void greet(SpeakableInterface contact) {
+ if (contact instanceof Human)
+ System.out.println("Hello " + contact.getName() + ", how are you?");
+ else
+ SpeakableInterface.super.greet(contact);
+ }
+
+ @Override
+ public void swim()
+ {
+ inWater = true;
+ System.out.println("I'm a " + this.getClass().getSimpleName() + " and I'm swimming.");
+ }
+
+ @Override
+ public boolean getSwimmingState()
+ {
+ return inWater;
+ }
+
+ @Override
+ public void emerge()
+ {
+ inWater = false;
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Creature.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Creature.java
new file mode 100644
index 0000000..1f63459
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Creature.java
@@ -0,0 +1,28 @@
+package fr.epita.assistants.creatureInterface;
+
+/**
+ * This abstract class provides a blueprint for creating creatures.
+ * All creatures extend this class.
+ */
+public abstract class Creature {
+ // The name of the creature
+ protected String name;
+
+ /**
+ * Constructor for the Creature class.
+ *
+ * @param name The name of the creature
+ */
+ Creature(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the name of the creature.
+ *
+ * @return The name of the creature
+ */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Dragon.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Dragon.java
new file mode 100644
index 0000000..49ee99d
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Dragon.java
@@ -0,0 +1,74 @@
+package fr.epita.assistants.creatureInterface;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class Dragon extends Creature implements MagicalInterface, SpeakableInterface, FlyingInterface {
+ int mana;
+ Collection<Spell> spells = new ArrayList<Spell>();
+
+ public Dragon(String name, int mana) {
+ super(name);
+ this.mana = mana;
+ }
+
+ @Override
+ public void hello() {
+ System.out.println("Hello, my name is " + this.name + " and I'm a Dragon.");
+ }
+
+ @Override
+ public void greet(SpeakableInterface contact) {
+ if (contact instanceof Dragon) {
+ System.out.println("Greetings Lord " + contact.getName() + ".");
+ MagicalInterface.super.doSomeSparkles();
+ }
+ else
+ SpeakableInterface.super.greet(contact);
+ }
+
+ @Override
+ public void fly() {
+ System.out.println("I'm a Dragon and I'm flying.");
+ }
+
+ @Override
+ public int getMana() {
+ return this.mana;
+ }
+
+ @Override
+ public Collection<Spell> getSpells() {
+ return spells;
+ }
+
+ @Override
+ public void addSpell(Spell spell) {
+ if (spell.getSpellType() == SpellType.WATER)
+ System.out.println("Dragon cannot learn WATER spells.");
+ else if (!spells.contains(spell))
+ {
+ spells.add(spell);
+ }
+ }
+
+ @Override
+ public void castSpell(Spell spell) {
+ if (spell.getSpellType() == SpellType.WATER)
+ System.out.println("Dragon cannot learn WATER spells.");
+ else if (!spells.contains(spell))
+ System.out.println(this.name + " does not know " + spell.name() + ".");
+ else if (spell.getManaCost() > this.mana)
+ System.out.println(this.name + " does not have enough mana.");
+ else {
+ System.out.println(this.name + " casted " + spell.name() + ".");
+ this.mana -= spell.getManaCost();
+ }
+ }
+
+ @Override
+ public void regenMana(int mana) {
+ this.mana += mana;
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Fish.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Fish.java
new file mode 100644
index 0000000..b109493
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Fish.java
@@ -0,0 +1,27 @@
+package fr.epita.assistants.creatureInterface;
+
+public class Fish extends Creature implements SwimmingInterface{
+ /**
+ * Constructor for the Creature class.
+ *
+ * @param name The name of the creature
+ */
+ Fish(String name) {
+ super(name);
+ }
+
+ @Override
+ public void swim() {
+ System.out.println("I'm a " + this.getClass().getSimpleName() + " and I'm swimming.");
+ }
+
+ @Override
+ public boolean getSwimmingState() {
+ return true;
+ }
+
+ @Override
+ public void emerge() {
+ throw new RuntimeException(name + " died.");
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/FlyingInterface.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/FlyingInterface.java
new file mode 100644
index 0000000..49ab154
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/FlyingInterface.java
@@ -0,0 +1,12 @@
+package fr.epita.assistants.creatureInterface;
+
+/**
+ * This interface provides methods for flying.
+ * Creatures that fly implement this interface.
+ */
+public interface FlyingInterface {
+ /**
+ * Prints "I'm a {CreatureClassName} and I'm flying."
+ */
+ void fly();
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Human.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Human.java
new file mode 100644
index 0000000..b29b49f
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Human.java
@@ -0,0 +1,8 @@
+package fr.epita.assistants.creatureInterface;
+
+public class Human extends BaseHuman {
+ public Human(String name)
+ {
+ super(name);
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mage.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mage.java
new file mode 100644
index 0000000..dab7630
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mage.java
@@ -0,0 +1,59 @@
+package fr.epita.assistants.creatureInterface;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+public class Mage extends BaseHuman implements MagicalInterface{
+ int mana;
+ Collection<Spell> spells = new ArrayList<Spell>();
+ public Mage(String name, int mana) {
+ super(name);
+ this.mana = mana;
+ }
+
+ @Override
+ public void greet(SpeakableInterface contact)
+ {
+ if (contact instanceof Mage)
+ System.out.println("I welcome you, " + contact.getName() + ".");
+ else
+ super.greet(contact);
+ }
+
+ @Override
+ public int getMana() {
+ return this.mana;
+ }
+
+ @Override
+ public Collection<Spell> getSpells() {
+ return spells;
+ }
+
+ @Override
+ public void addSpell(Spell spell) {
+ if (!spells.contains(spell))
+ {
+ spells.add(spell);
+ }
+ }
+
+ @Override
+ public void castSpell(Spell spell) {
+ if (!spells.contains(spell))
+ System.out.println(this.name + " does not know " + spell.name() + ".");
+ else if (spell.getManaCost() > this.mana)
+ System.out.println(this.name + " does not have enough mana.");
+ else {
+ System.out.println(this.name + " casted " + spell.name() + ".");
+ this.mana -= spell.getManaCost();
+ }
+ }
+
+ @Override
+ public void regenMana(int mana) {
+ if (inWater)
+ mana = (int)(mana * 0.9);
+ this.mana += mana;
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/MagicalInterface.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/MagicalInterface.java
new file mode 100644
index 0000000..d7530ab
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/MagicalInterface.java
@@ -0,0 +1,56 @@
+package fr.epita.assistants.creatureInterface;
+
+import java.util.Collection;
+
+/**
+ * This interface provides methods for creatures that are Magical!
+ * Creatures that implement this interface have magical mana and spells.
+ */
+public interface MagicalInterface {
+ /**
+ * Get the mana of the creature.
+ *
+ * @return The mana of the creature
+ */
+ int getMana();
+
+ /**
+ * Get the spells of the creature.
+ *
+ * @return The spells of the creature
+ */
+ Collection<Spell> getSpells();
+
+ /**
+ * Add a spell to the creature.
+ * If the spell is already present, it will not be added.
+ * Be sure to check that the creature <strong>can</strong> learn the spell before adding it.
+ * Prints a message if the creature cannot learn the spell.
+ *
+ * @param spell The spell to add
+ */
+ void addSpell(Spell spell);
+
+ /**
+ * Cast a spell.
+ * If the creature knows the spell and has enough mana, the spell is cast.
+ * Otherwise, prints a message indicating the reason.
+ *
+ * @param spell The spell to cast
+ */
+ void castSpell(Spell spell);
+
+ /**
+ * Regenerate an amount of mana.
+ *
+ * @param mana The amount of mana to regenerate
+ */
+ void regenMana(int mana);
+
+ /**
+ * Do some sparkles ✨✨✨
+ */
+ default void doSomeSparkles() {
+ System.out.println("*sparkling effects*");
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mermaid.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mermaid.java
new file mode 100644
index 0000000..d086e8d
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Mermaid.java
@@ -0,0 +1,110 @@
+package fr.epita.assistants.creatureInterface;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class Mermaid extends Creature implements SpeakableInterface, MagicalInterface, SwimmingInterface {
+ int mana;
+ Collection<Spell> spells = new ArrayList<Spell>();
+ boolean swimmingState;
+
+ private String make_name(BaseHuman baseHuman, Fish fish) {
+ StringBuilder name = new StringBuilder();
+ name.append(baseHuman.getName().substring(0, 1).toUpperCase()).append(baseHuman.getName().substring(1).toLowerCase());
+ name.append(fish.getName().toLowerCase());
+ return new String(name);
+ }
+
+ public Mermaid(BaseHuman baseHuman, Fish fish)
+ {
+ super("");
+ this.name = make_name(baseHuman, fish);
+ if (baseHuman instanceof Mage)
+ {
+ for (Spell s : ((Mage) baseHuman).getSpells())
+ {
+ if (s.getSpellType() == SpellType.FIRE)
+ {
+ System.out.println(this.name + " forgot the spell " + s.name() + ".");
+ }
+ else
+ {
+ addSpell(s);
+ }
+ }
+ }
+ this.swimmingState = baseHuman.getSwimmingState();
+ this.mana = 0;
+ }
+
+ @Override
+ public void hello() {
+ System.out.println("Hello, my name is " + this.name + " and I'm a Mermaid.");
+ }
+
+ @Override
+ public void greet(SpeakableInterface contact) {
+ if (contact instanceof Mermaid)
+ System.out.println("Dear " + contact.getName() + ", welcome.");
+ else
+ SpeakableInterface.super.greet(contact);
+ }
+
+ @Override
+ public int getMana() {
+ return this.mana;
+ }
+
+ @Override
+ public Collection<Spell> getSpells() {
+ return spells;
+ }
+
+ @Override
+ public void addSpell(Spell spell) {
+ if (spell.getSpellType() == SpellType.FIRE)
+ System.out.println("Mermaid cannot learn FIRE spells.");
+ else if (!spells.contains(spell)) {
+ spells.add(spell);
+ }
+ }
+
+ @Override
+ public void castSpell(Spell spell) {
+ if (spell.getSpellType() == SpellType.FIRE)
+ System.out.println("Mermaid cannot learn FIRE spells.");
+ else if (!spells.contains(spell))
+ System.out.println(this.name + " does not know " + spell.name() + ".");
+ else if (spell.getSpellType() == SpellType.WATER && swimmingState && spell.getManaCost() * 0.6 <= this.mana) {
+ this.mana -= (int) (spell.getManaCost() * 0.6);
+ System.out.println(this.name + " casted " + spell.name() + ".");
+ } else if (spell.getManaCost() > this.mana)
+ System.out.println(this.name + " does not have enough mana.");
+ else {
+ System.out.println(this.name + " casted " + spell.name() + ".");
+ this.mana -= spell.getManaCost();
+ }
+ }
+
+ @Override
+ public void regenMana(int mana) {
+ this.mana += mana;
+ }
+
+ @Override
+ public void swim() {
+ swimmingState = true;
+ System.out.println("I'm a Mermaid and I'm swimming.");
+ }
+
+ @Override
+ public boolean getSwimmingState() {
+ return swimmingState;
+ }
+
+ @Override
+ public void emerge() {
+ swimmingState = false;
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpeakableInterface.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpeakableInterface.java
new file mode 100644
index 0000000..cc10988
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpeakableInterface.java
@@ -0,0 +1,47 @@
+package fr.epita.assistants.creatureInterface;
+
+import java.util.List;
+
+/**
+ * This interface provides communication methods for the objects of the class
+ * that implements it. Classes adopting this interface instantiate objects
+ * capable of communication.
+ */
+public interface SpeakableInterface {
+ /**
+ * Returns the name of the object that can speak
+ */
+ String getName();
+
+ /**
+ * Prints "Hello, my name is {creatureName} and I'm a {creatureClassName}."
+ */
+ void hello();
+
+ /**
+ * Greets the contact
+ * The default implementation greets the contact based on its type
+ * @param contact the creature to greet
+ */
+ default void greet(SpeakableInterface contact) {
+ if (contact instanceof Mage)
+ System.out.println("Salutations " + contact.getName() + ", keeper of Arcane secrets.");
+ else if (contact instanceof Human)
+ System.out.println("Salutations " + contact.getName() + " the human.");
+ else if (contact instanceof Dragon)
+ System.out.println("Salutations " + contact.getName() + ", keeper of Ancient treasures.");
+ else if (contact instanceof Mermaid)
+ System.out.println("Salutations " + contact.getName() + ", keeper of the Seas.");
+ }
+
+
+ /**
+ * Allows all speakers in the collection to say hello as explained in the hello() method
+ * @param speakers the list of creatures that can speak
+ */
+ static void helloAll(List<SpeakableInterface> speakers) {
+ for (SpeakableInterface speaker : speakers) {
+ speaker.hello();
+ }
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Spell.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Spell.java
new file mode 100644
index 0000000..87fe68a
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/Spell.java
@@ -0,0 +1,48 @@
+package fr.epita.assistants.creatureInterface;
+
+/**
+ * This enum represents a spell that some creature can cast.
+ * Refer to the subject for more information about enum with behavior.
+ */
+public enum Spell {
+ FIREBALL(40, SpellType.FIRE, "Launches a sphere of fire that explodes upon impact."),
+ HEAL(30, SpellType.NEUTRAL, "Channels divine energy to restore health."),
+ MAGIC_SHIELD(15, SpellType.NEUTRAL, "Summons an arcane shield that reflects attacks."),
+ TIDAL_WAVE(30, SpellType.WATER, "Summons a huge wave of water that crashes down dealing damage.");
+
+ /**
+ * The cost of the spell in mana.
+ */
+ private final int manaCost;
+
+ /**
+ * The type of the spell.
+ */
+ private final SpellType spellType;
+
+ /**
+ * The description of the spell.
+ */
+ private final String description;
+
+ Spell(int manaCost, SpellType spellType, String description) {
+ this.manaCost = manaCost;
+ this.spellType = spellType;
+ this.description = description;
+ }
+
+ public int getManaCost() {
+ return manaCost;
+ }
+
+ public SpellType getSpellType() {
+ return spellType;
+ }
+
+ /**
+ * This method prints a description of the spell and its mana cost.
+ */
+ public void what() {
+ System.out.println(this.description + "\tUses " + getManaCost() + " mana.");
+ }
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpellType.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpellType.java
new file mode 100644
index 0000000..53cca2a
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SpellType.java
@@ -0,0 +1,11 @@
+package fr.epita.assistants.creatureInterface;
+
+/**
+ * This enumeration provides the types of spells.
+ * Do not forget that creatures have restrictions on the types of spells they can learn.
+ */
+public enum SpellType {
+ FIRE,
+ WATER,
+ NEUTRAL,
+}
diff --git a/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SwimmingInterface.java b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SwimmingInterface.java
new file mode 100644
index 0000000..ede4d31
--- /dev/null
+++ b/graphs/java/creatureInterface/src/main/java/fr/epita/assistants/creatureInterface/SwimmingInterface.java
@@ -0,0 +1,25 @@
+package fr.epita.assistants.creatureInterface;
+
+/**
+ * This interface provides methods for swimming.
+ * Creatures that swim implement this interface.
+ */
+public interface SwimmingInterface {
+ /**
+ * Prints "I'm a {CreatureClassName} and I'm swimming."
+ */
+ void swim();
+
+ /**
+ * Returns true if the creature is swimming.
+ * It is up to the implementing class to determine the conditions for swimming.
+ *
+ * @return True if the creature is swimming
+ */
+ boolean getSwimmingState();
+
+ /**
+ * Emerges from the water.
+ */
+ void emerge();
+}