diff --git a/DEV3.2/CM1/01_Division/Main.class b/DEV3.2/CM1/01_Division/Main.class new file mode 100644 index 0000000..a465132 Binary files /dev/null and b/DEV3.2/CM1/01_Division/Main.class differ diff --git a/DEV3.2/CM1/01_Division/Main.java b/DEV3.2/CM1/01_Division/Main.java new file mode 100644 index 0000000..28b2f3a --- /dev/null +++ b/DEV3.2/CM1/01_Division/Main.java @@ -0,0 +1,31 @@ +import java.util.ArrayDeque; +import java.util.Queue; + +public class Main { + public static void main(String[] args) { + ArrayDeque textes = new ArrayDeque<>(); + ArrayDeque entiers = new ArrayDeque<>(); + + for (String chaine : args) { + try { + Integer entier = new Integer(Integer.parseInt(chaine)); + + entiers.addLast(entier.intValue()); + } catch (NumberFormatException e) { + textes.addLast(chaine); + } + } + + for (Integer entier : entiers) { + System.out.print(entier + " "); + } + + System.out.println(""); + + for (String texte : textes) { + System.out.print(texte + " "); + } + + System.out.println(""); + } +} \ No newline at end of file diff --git a/DEV3.2/TP08/02_Authentification/ABR.class b/DEV3.2/TP08/02_Authentification/ABR.class new file mode 100644 index 0000000..824c89e Binary files /dev/null and b/DEV3.2/TP08/02_Authentification/ABR.class differ diff --git a/DEV3.2/TP08/02_Authentification/ABR.java b/DEV3.2/TP08/02_Authentification/ABR.java new file mode 100644 index 0000000..ada1da0 --- /dev/null +++ b/DEV3.2/TP08/02_Authentification/ABR.java @@ -0,0 +1,112 @@ +public class ABR { + + private String valeur; + private ABR filsGauche; + private ABR filsDroit; + private int compteur = 0; + + public ABR() { + this.valeur = null; + this.filsDroit = null; + this.filsGauche = null; + } + + public ABR(String valeur) { + this.valeur = valeur; + } + + + public boolean authentifier(String id, String password) { + + // Si le noeud courant est vide, aller dans le fils gauche + if (this.valeur == null) { + if (this.filsGauche != null) { + return this.filsGauche.authentifier(id, password); + } + return false; // rien dans l'arbre + } + + // Si on trouve l'id au noeud courant + if (this.valeur.equals(id)) { + if (this.filsDroit != null && this.filsDroit.valeur.equals(password)) { + return true; + } + return false; + } + + // Sinon, continuer à gauche + if (this.filsGauche != null) { + return this.filsGauche.authentifier(id, password); + } + + return false; +} + + + public void supprimer(String id) { + if (this.filsGauche != null) { + if (this.filsGauche.valeur.equals(id)) { + if (this.filsGauche.filsGauche != null) { + this.filsGauche = this.filsGauche.filsGauche; + } else { + this.filsGauche = null; + } + System.out.println("Suppression effectuée."); + } else { + this.filsGauche.supprimer(id); + } + } + } + + + public void ajouterUtilisateur(String id, String password) { + if (this.filsGauche != null && this.filsGauche.equals(id)) { + System.out.println("Valeur déjà présente."); + return; + } + + if (this.filsGauche != null) { + this.filsGauche.ajouterUtilisateur(id, password); + } else { + this.filsGauche = new ABR(id); + this.filsGauche.filsDroit = new ABR(password); + } + } + + public boolean estPresent(String id) { + if (this.filsGauche == null) { + return false; + } + + if (this.compteur == 0) { + this.compteur++; + this.filsGauche.estPresent(id); + } + + if (this.compteur != 0 && this.valeur == null) { + return false; + } + + if (this.valeur.equals(id)) { + return true; + } else { + return this.filsGauche.estPresent(id); + } + } + + public String toString() { + String aRenvoyer = ""; + + if (this.filsDroit == null && this.filsGauche == null) { + return ""; + } else { + if (this.filsGauche == null) { + return ""; + } else { + aRenvoyer += "Identifiant : " + this.filsGauche.valeur + " / Mot de passe : " + this.filsGauche.filsDroit.valeur + "\n"; + return aRenvoyer + this.filsGauche.toString(); + } + } + } + +} \ No newline at end of file diff --git a/DEV3.2/TP08/02_Authentification/Authentification.class b/DEV3.2/TP08/02_Authentification/Authentification.class index a94c555..de7814e 100644 Binary files a/DEV3.2/TP08/02_Authentification/Authentification.class 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 index 7bd5462..e6f0aef 100644 --- a/DEV3.2/TP08/02_Authentification/Authentification.java +++ b/DEV3.2/TP08/02_Authentification/Authentification.java @@ -1,42 +1,43 @@ import java.awt.*; -import java.util.HashMap; -import java.util.Map; import java.io.*; public class Authentification { - private Map dictionnaire; + private ABR dictionnaire; public Authentification() { - this.dictionnaire = new HashMap<>(); + this.dictionnaire = new ABR(); } public void ajouter(String username, String password) { - if (this.dictionnaire.get(username) != null) { + if (this.dictionnaire.estPresent(username)) { System.out.println("L'utilisateur '" + username + "' existe déjà."); } else { - this.dictionnaire.put(username, password); + this.dictionnaire.ajouterUtilisateur(username, password); System.out.println("Utilisateur ajouté."); } + System.out.println(this.dictionnaire); } public void authentifier(String username, String password) { - if (this.dictionnaire.get(username) == null) { + if (!this.dictionnaire.estPresent(username)) { System.out.println("L'utilisateur '" + username + "' n'existe pas."); - } else if (!this.dictionnaire.get(username).equals(password)) { + } else if (!this.dictionnaire.authentifier(username, password)) { System.out.println("Le mot de passe est incorrect."); } else { System.out.println("L'utilisateur '" + username + "' est authentifié."); } + System.out.println(this.dictionnaire); } public void supprimer(String username) { - if (this.dictionnaire.get(username) == null) { + if (!this.dictionnaire.estPresent(username)) { System.out.println("L'utilisateur '" + username + "' n'existe pas."); } else { - this.dictionnaire.remove(username); + this.dictionnaire.supprimer(username); System.out.println("L'utilisateur '" + username + "' a été supprimé"); } + System.out.println(this.dictionnaire); } public static void main(String[] args) { @@ -63,7 +64,7 @@ public class Authentification { auth.authentifier(ligne[1], ligne[2]); } else if (input.equals("del")) { auth.supprimer(ligne[1]); - } else if (input.equals("quit")) { + } else. if (input.equals("quit")) { } else { System.out.println("Commande non reconnue."); diff --git a/DEV4.5/TP01_Mise_en_page/01_Chat/v1/activity_main.xml b/DEV4.5/TP01_Mise_en_page/01_Chat/v1/activity_main.xml new file mode 100644 index 0000000..c8c4d1d --- /dev/null +++ b/DEV4.5/TP01_Mise_en_page/01_Chat/v1/activity_main.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + +