ANDROID WE
This commit is contained in:
BIN
DEV3.2/CM1/01_Division/Main.class
Normal file
BIN
DEV3.2/CM1/01_Division/Main.class
Normal file
Binary file not shown.
31
DEV3.2/CM1/01_Division/Main.java
Normal file
31
DEV3.2/CM1/01_Division/Main.java
Normal file
@@ -0,0 +1,31 @@
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ArrayDeque<String> textes = new ArrayDeque<>();
|
||||
ArrayDeque<Integer> 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("");
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/TP08/02_Authentification/ABR.class
Normal file
BIN
DEV3.2/TP08/02_Authentification/ABR.class
Normal file
Binary file not shown.
112
DEV3.2/TP08/02_Authentification/ABR.java
Normal file
112
DEV3.2/TP08/02_Authentification/ABR.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -1,42 +1,43 @@
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.io.*;
|
||||
|
||||
public class Authentification {
|
||||
|
||||
private Map<String, String> 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.");
|
||||
|
||||
Reference in New Issue
Block a user