diff --git a/DEV3.2/TP08/01_Tri/Tri.class b/DEV3.2/TP08/01_Tri/Tri.class new file mode 100644 index 0000000..c69f583 Binary files /dev/null and b/DEV3.2/TP08/01_Tri/Tri.class differ diff --git a/DEV3.2/TP08/01_Tri/Tri.java b/DEV3.2/TP08/01_Tri/Tri.java new file mode 100644 index 0000000..1d26d98 --- /dev/null +++ b/DEV3.2/TP08/01_Tri/Tri.java @@ -0,0 +1,67 @@ +import java.awt.*; + +public class Tri { + + private double valeur; + private Tri filsGauche; + private Tri filsDroit; + private boolean estVide; + + public Tri() { + this.estVide = true; + } + + public Tri(double valeur) { + this.estVide = false; + this.valeur = valeur; + } + + public void ajouter(double valeur) { + if (this.estVide) { + this.valeur = valeur; + this.estVide = false; + return; + } + + if (valeur < this.valeur) { + if (this.filsGauche == null) { + this.filsGauche = new Tri(); + } + filsGauche.ajouter(valeur); + } else { + if (this.filsDroit == null) { + this.filsDroit = new Tri(); + } + filsDroit.ajouter(valeur); + } + } + + public String toString() { + String aRenvoyer = ""; + + if (this.filsGauche != null) { + aRenvoyer += this.filsGauche.toString(); + } + + aRenvoyer += this.valeur + " "; + + if (this.filsDroit != null) { + aRenvoyer += this.filsDroit.toString(); + } + + return aRenvoyer; + } + + + public static void main(String[] args) { + Tri racine = new Tri(); + + for (String chaine : args) { + racine.ajouter(Double.parseDouble(chaine)); + } + + System.out.println(racine); + } + + +} \ No newline at end of file diff --git a/DEV3.2/TP08/02_Authentification/Authentification.class b/DEV3.2/TP08/02_Authentification/Authentification.class new file mode 100644 index 0000000..233968e Binary files /dev/null and b/DEV3.2/TP08/02_Authentification/Authentification.class differ diff --git a/DEV3.2/TP08/02_Authentification/Authentification.java b/DEV3.2/TP08/02_Authentification/Authentification.java new file mode 100644 index 0000000..d8b1b03 --- /dev/null +++ b/DEV3.2/TP08/02_Authentification/Authentification.java @@ -0,0 +1,70 @@ +import java.awt.*; +import java.util.HashMap; +import java.util.Map; +import java.io.*; + +public class Authentification { + + private Map dictionnaire; + + public Authentification() { + this.dictionnaire = new HashMap<>(); + } + + public void ajouter(String username, String password) { + if (this.dictionnaire.get(username) != null) { + System.out.println("L'utilisateur '" + username + "' existe déjà."); + } else { + this.dictionnaire.put(username, password); + } + } + + public void authentifier(String username, String password) { + if (this.dictionnaire.get(username) == null) { + System.out.println("L'utilisateur '" + username + "' n'existe pas."); + } else if (this.dictionnaire.get(username) != password) { + System.out.println("Le mot de passe est incorrect."); + } else { + System.out.println("L'utilisateur '" + username + "' est authentifié."); + } + } + + public void supprimer(String username) { + if (this.dictionnaire.get(username) == null) { + System.out.println("L'utilisateur '" + username + "' n'existe pas."); + } else { + this.dictionnaire.remove(username); + System.out.println("L'utilisateur '" + username + "' a été supprimé"); + } + } + + public static void main(String[] args) { + Authentification auth = new Authentification(); + + BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); + + try { + String input = ""; + + while (!input.equals("quit")) { + String[] ligne = console.readLine().split(" "); + input = ligne[0]; + + System.out.print("> "); + if (input.equals("add")) { + auth.ajouter(ligne[1], ligne[2]); + } else if (input.equals("auth")) { + auth.authentifier(ligne[1], ligne[2]); + } else if (input.equals("del")) { + auth.supprimer(ligne[1]); + } else { + System.out.println("Commande non reconnue."); + } + } + + } catch (IOException e) { + System.err.println("Erreur de la console"); + } + } + +} \ No newline at end of file