ANDROID WE

This commit is contained in:
Simoes Lukas
2026-01-22 14:28:35 +01:00
parent a975ac1d33
commit b2ebfe848e
7 changed files with 202 additions and 11 deletions

Binary file not shown.

View 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("");
}
}

Binary file not shown.

View 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();
}
}
}
}

View File

@@ -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.");

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#555"
android:padding="10dp"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="660dp"
android:layout_gravity="top"
android:background="@color/white"
android:inputType="textMultiLine"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:textSize="20dp"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>