From 67371a73ea4d416c29e100c11c8707e1f52271a3 Mon Sep 17 00:00:00 2001 From: Samuel Turpin <samuel.turpin.etu@univ-lille.fr> Date: Wed, 29 May 2024 16:15:15 +0200 Subject: [PATCH] ajout du travail du ds2, modification tp09 --- src/ds2/Capacity.java | 28 ++++++++++++ src/ds2/Dragon.java | 76 +++++++++++++++++++++++++++++++ src/ds2/Komodo.java | 38 ++++++++++++++++ src/tp09/LogInManagement.java | 29 ++++++++++-- src/tp09/WrongLoginException.java | 8 ++++ 5 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 src/ds2/Capacity.java create mode 100644 src/ds2/Dragon.java create mode 100644 src/ds2/Komodo.java diff --git a/src/ds2/Capacity.java b/src/ds2/Capacity.java new file mode 100644 index 0000000..a56847d --- /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 0000000..5edca51 --- /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 0000000..3922a0d --- /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 77aec2d..fc1794f 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 49fd0c3..77edce6 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) { -- GitLab