diff --git a/src/ds2/Capacity.java b/src/ds2/Capacity.java new file mode 100644 index 0000000000000000000000000000000000000000..a56847d8270b2666387acc8f0949b9a25c68cc3e --- /dev/null +++ b/src/ds2/Capacity.java @@ -0,0 +1,28 @@ +package ds2; + +public enum Capacity +{ + CLIMBER, VENOM, WHIPTAIL; + + @Override + public String toString() + { + String rep = ""; + switch (this) + { + case CLIMBER: + rep = "I can attack from trees. . ."; + break; + case VENOM: + rep = "I can poison preys. . ."; + break; + case WHIPTAIL: + rep = "I can attack from trees. . ."; + break; + default: + rep = "NULL CAPACITY"; + break; + } + return rep; + } +} \ No newline at end of file diff --git a/src/ds2/Dragon.java b/src/ds2/Dragon.java new file mode 100644 index 0000000000000000000000000000000000000000..5edca5147d92a2d177b2b83dd7d0aab8924e20b0 --- /dev/null +++ b/src/ds2/Dragon.java @@ -0,0 +1,76 @@ +package ds2; + +import java.time.LocalDate; +import java.util.Objects; +import java.util.Random; + +public class Dragon +{ + private Capacity capacity; + private final String NAME; + private final LocalDate BIRTH; + protected int power; + private Dragon father; + private Dragon mother; + public static final Random rnd = new Random(); + boolean isPowerfull = father.power > mother.power; + + public Dragon(String n, Dragon fath, Dragon moth) + { + this.capacity = null; + this.NAME = n; + this.BIRTH = LocalDate.now(); + this.power = rnd.nextInt(0, isPowerfull ? father.power : mother.power); + this.father = fath; + this.mother = moth; + } + + public Dragon(String n) + { + this(n, null, null); + this.power = rnd.nextInt(0, 100); + } + + public String getNAME() { + return NAME; + } + + public LocalDate getBIRTH() { + return BIRTH; + } + + public void setCapacity() + { + if(this.father.power == this.mother.power) + { + Capacity[] c = {this.father.capacity, this.mother.capacity}; + this.capacity = c[rnd.nextInt(c.length - 1)]; + } + if(this.father.power > this.mother.power) + { + this.capacity = this.father.capacity; + } + else if(this.father.power < this.mother.power) + { + this.capacity = this.mother.capacity; + } + else //Née sous X + { + Capacity[] c = Capacity.values(); + this.capacity = c[rnd.nextInt(c.length - 1)]; + } + } + + @Override + public boolean equals(Object obj) + { + Dragon dr = (Dragon) obj; + return this.NAME.equals(dr.NAME); + } + + @Override + public int hashCode() + { + return Objects.hash(); + } +} \ No newline at end of file diff --git a/src/ds2/Komodo.java b/src/ds2/Komodo.java new file mode 100644 index 0000000000000000000000000000000000000000..3922a0dd26464390193ed498701f8345594f6786 --- /dev/null +++ b/src/ds2/Komodo.java @@ -0,0 +1,38 @@ +package ds2; + +import java.util.ArrayList; +import java.util.List; + +public class Komodo +{ + private List<Dragon> population = new ArrayList<>(); + + public void add(Dragon d) + { + this.population.add(d); + } + + public void remove(Dragon dr) + { + this.population.remove(dr); + } + + public void remove(String name) + { + this.population.remove(search(name)); + } + + public Dragon search(String name) + { + for(Dragon drag : this.population) + { + if(drag.getNAME().equals(name)) + { + System.out.println("Dragon found"); + return drag; + } + } + System.out.println("Dragon not found"); + return null; + } +} \ No newline at end of file diff --git a/src/tp09/LogInManagement.java b/src/tp09/LogInManagement.java index 77aec2d992ab93c6c2fa4c950f2a69b9dddffae2..fc1794f38e25306a69ba9f34078fce0d69518c38 100644 --- a/src/tp09/LogInManagement.java +++ b/src/tp09/LogInManagement.java @@ -1,17 +1,36 @@ package tp09; +import java.util.Scanner; + public class LogInManagement { public static final String LOGIN = "samuel.turpin.etu"; public static final String PWD = "poneymagique"; - public LogInManagement(String log, String pwd) - { - - } - public boolean getUserPwd() { return true; } + + public static void main(String[] args) + { + boolean connected = false; + Scanner scan = new Scanner(System.in); + while(!connected) + { + String log = scan.next(); + String pass = scan.next(); + + try + { + if(log.equals(LOGIN) && pass.equals(PWD)) + { + System.out.println("Mot de passe correct !"); + } + } catch (Exception e) { + System.out.println("Erreur du Mot de passe !"); + System.out.println("Veuillez réésayer..."); + } + } + } } \ No newline at end of file diff --git a/src/tp09/WrongLoginException.java b/src/tp09/WrongLoginException.java index 49fd0c3cd1d1b8e5b482f2b60c87572e2427edd1..77edce6ff35a2aa395aa35f9c7120375ee89453d 100644 --- a/src/tp09/WrongLoginException.java +++ b/src/tp09/WrongLoginException.java @@ -2,6 +2,14 @@ package tp09; public class WrongLoginException extends Exception { + private String LOGIN; + + public boolean init(String base, String log) + { + + return false; + } + @Override public synchronized Throwable initCause(Throwable cause) {