ajout crypto

This commit is contained in:
2025-03-31 10:06:09 +02:00
parent 731020a934
commit bff1a74ae7
680 changed files with 14849 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
/*Felix-vimalaratnam
Patrick*/
public class Division {
public static boolean IsInt(String c){
try{
int a = Integer.parseInt(c);
}catch(Exception e){
return Boolean.FALSE;
}
return Boolean.TRUE;
}
public static String toString(FileTableau f){
String ligne = "";
while(f.taille() != 0){
ligne = ligne + " " + f.retirer().toString();
}
return ligne;
}
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Veuillez fournir une expression en notation polonaise inversée.");
return;
}
FileTableau<Integer> ligne1 = new FileTableau<>();
FileTableau<String> ligne2 = new FileTableau<>();
for (int i = 0; i < args.length; i++){
if (IsInt(args[i])){
ligne1.ajouter(Integer.parseInt(args[i]));
}
else{
ligne2.ajouter(args[i]);
}
}
System.out.println(toString(ligne1));
System.out.println(toString(ligne2));
}
}

View File

@@ -0,0 +1,50 @@
/*Felix-vimalaratnam
Patrick*/
public class Division2 {
public static boolean IsInt(String c){
try{
int a = Integer.parseInt(c);
}catch(Exception e){
return Boolean.FALSE;
}
return Boolean.TRUE;
}
public static String toString(FileTableau2 f){
String ligne = "";
while(f.taille() != 0){
ligne = ligne + " " + f.retirer().toString();
}
return ligne;
}
public static String toStringpourString(FileTableau2 f){
String ligne = "";
while(f.taille() != 0){
f.removeif();
ligne = ligne + " " + f.retirer().toString();
}
return ligne;
}
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Veuillez fournir une expression en notation polonaise inversée.");
return;
}
FileTableau2<Integer> ligne1 = new FileTableau2<>();
FileTableau2<String> ligne2 = new FileTableau2<>();
for (int i = 0; i < args.length; i++){
if (IsInt(args[i])){
ligne1.ajouter(Integer.parseInt(args[i]));
}
else{
ligne2.ajouter(args[i]);
}
}
System.out.println(toString(ligne1));
System.out.println(toStringpourString(ligne2));
}
}

View File

@@ -0,0 +1,21 @@
/*Felix-vimalaratnam
Patrick*/
/**
* Une structure de données abstraite qui contient des entiers entre 0 et 100. Aucune
* valeur ne peut apparaître plusieurs fois dans cette structure.
*
* @version 1.0 15 January 2025
* @author Luc Hernandez
*/
public interface Ensemble {
/**
* Ajoute une nouvelle valeur à la structure.
*
* @param element la nouvelle valeur
* @return true si la nouvelle valeur a été ajoutée, false si elle était déjà présente
* @throws IllegalArgumentException si l'argument n'est pas compris entre 0 et 100
*/
public boolean ajouter(byte element);
public boolean comparer(byte element);
}

9
DEV3.2/DEV32/File.java Normal file
View File

@@ -0,0 +1,9 @@
/*Felix-vimalaratnam
Patrick*/
public interface File<E> {
void ajouter(E element); // Ajoute un élément en fin de la file
E retirer(); // Retire et retourne l'élément en tête de la file
int taille(); // Retourne la taille de la file
boolean estVide(); // Vérifie si la file est vide
}

10
DEV3.2/DEV32/File2.java Normal file
View File

@@ -0,0 +1,10 @@
/*Felix-vimalaratnam
Patrick*/
public interface File2<E> {
void ajouter(E element); // Ajoute un élément en fin de la file
E retirer(); // Retire et retourne l'élément en tête de la file
void removeif(); //retire si il a un tiret
int taille(); // Retourne la taille de la file
boolean estVide(); // Vérifie si la file est vide
}

View File

@@ -0,0 +1,44 @@
/*Felix-vimalaratnam
Patrick*/
public class FileTableau<E> implements File<E> {
private static final int CAPACITE_INITIALE = 20;
private E[] elements;
private int taille = 0;
private int debut = 0;
private int fin = 0;
@SuppressWarnings("unchecked")
public FileTableau() {
elements = (E[]) new Object[CAPACITE_INITIALE]; // Création du tableau initial
}
@Override
public void ajouter(E element) {
elements[fin] = element;
fin = (fin + 1);
taille++;
}
@Override
public E retirer() {
if (estVide()) {
throw new IllegalStateException("La file est vide");
}
E element = elements[debut];
elements[debut] = null; // Supprime la référence pour éviter les fuites de mémoire
debut = (debut + 1);
taille--;
return element;
}
@Override
public int taille() {
return taille;
}
@Override
public boolean estVide() {
return taille == 0;
}
}

View File

@@ -0,0 +1,54 @@
/*Felix-vimalaratnam
Patrick*/
public class FileTableau2<E> implements File2<E> {
private static final int CAPACITE_INITIALE = 20;
private E[] elements;
private int taille = 0;
private int debut = 0;
private int fin = 0;
@SuppressWarnings("unchecked")
public FileTableau2() {
elements = (E[]) new Object[CAPACITE_INITIALE]; // Création du tableau initial
}
@Override
public void ajouter(E element) {
elements[fin] = element;
fin = (fin + 1);
taille++;
}
@Override
public void removeif() {
E element = elements[debut];
if (element.toString().charAt(0) == '-') {
elements[debut] = null; // Supprime la référence pour éviter les fuites de mémoire
debut = (debut + 1);
taille--;
}
}
@Override
public E retirer() {
if (estVide()) {
throw new IllegalStateException("La file est vide");
}
E element = elements[debut];
elements[debut] = null; // Supprime la référence pour éviter les fuites de mémoire
debut = (debut + 1);
taille--;
return element;
}
@Override
public int taille() {
return taille;
}
@Override
public boolean estVide() {
return taille == 0;
}
}

View File

@@ -0,0 +1,58 @@
import java.util.LinkedList;
import java.util.Queue;
public class Bulles {
// Méthode bulle : effectue un parcours
public static boolean bulle(Queue<Integer> source, Queue<Integer> destination) {
boolean changed = false;
if (source.isEmpty()) {
return false;
}
int prev = source.poll(); // On récupère le premier élément
while (!source.isEmpty()) {
int current = source.poll();
if (prev > current) { // Si les deux éléments ne sont pas dans l'ordre
changed = true;
destination.add(current); // Ajouter le plus petit élément
prev = prev; // Garder prev pour continuer la comparaison
} else {
destination.add(prev);
prev = current;
}
}
destination.add(prev); // Ajouter le dernier élément
return changed;
}
// Méthode tri : utilise bulle pour trier complètement la file
public static void tri(Queue<Integer> file) {
Queue<Integer> intermediaire = new LinkedList<>();
boolean changed;
do {
changed = bulle(file, intermediaire);
// Inverser les files pour un nouveau parcours
Queue<Integer> temp = file;
file = intermediaire;
intermediaire = temp;
} while (changed);
// Les valeurs triées se trouvent dans `file`
while (!file.isEmpty()) {
System.out.print(file.poll() + " ");
}
System.out.println();
}
public static void main(String[] args) {
// Exemple : lecture des entiers passés en arguments
Queue<Integer> file = new LinkedList<>();
for (String arg : args) {
file.add(Integer.parseInt(arg));
}
// Tri et affichage du résultat
tri(file);
}
}

View File

@@ -0,0 +1,55 @@
import java.util.LinkedList;
import java.util.Queue;
public class GeneriqueBulles<T extends Comparable<T>> {
// Méthode bulle générique
public static <T extends Comparable<T>> boolean bulle(Queue<T> source, Queue<T> destination) {
boolean changed = false;
if (source.isEmpty()) {
return false;
}
T prev = source.poll();
while (!source.isEmpty()) {
T current = source.poll();
if (prev.compareTo(current) > 0) {
changed = true;
destination.add(current);
prev = prev;
} else {
destination.add(prev);
prev = current;
}
}
destination.add(prev);
return changed;
}
// Méthode tri générique
public static <T extends Comparable<T>> void tri(Queue<T> file) {
Queue<T> intermediaire = new LinkedList<>();
boolean changed;
do {
changed = bulle(file, intermediaire);
Queue<T> temp = file;
file = intermediaire;
intermediaire = temp;
} while (changed);
while (!file.isEmpty()) {
System.out.print(file.poll() + " ");
}
System.out.println();
}
public static void main(String[] args) {
Queue<String> file = new LinkedList<>();
file.add("Banane");
file.add("Pomme");
file.add("Orange");
file.add("Ananas");
tri(file);
}
}

View File

@@ -0,0 +1,105 @@
public class SimpleDeque<T> implements MinimalDeque<T> {
private static class Node<T> {
T value;
Node<T> next;
Node<T> prev;
Node(T value) {
this.value = value;
}
}
private Node<T> head;
private Node<T> tail;
private int size;
public SimpleDeque() {
head = null;
tail = null;
size = 0;
}
@Override
public void addFirst(T element) {
Node<T> newNode = new Node<>(element);
if (isEmpty()) {
head = tail = newNode;
} else {
newNode.next = head;
head.prev = newNode;
head = newNode;
}
size++;
}
@Override
public void addLast(T element) {
Node<T> newNode = new Node<>(element);
if (isEmpty()) {
head = tail = newNode;
} else {
newNode.prev = tail;
tail.next = newNode;
tail = newNode;
}
size++;
}
@Override
public T removeFirst() {
if (isEmpty()) {
throw new IllegalStateException("Deque is empty");
}
T value = head.value;
head = head.next;
if (head != null) {
head.prev = null;
} else {
tail = null;
}
size--;
return value;
}
@Override
public T removeLast() {
if (isEmpty()) {
throw new IllegalStateException("Deque is empty");
}
T value = tail.value;
tail = tail.prev;
if (tail != null) {
tail.next = null;
} else {
head = null;
}
size--;
return value;
}
@Override
public T peekFirst() {
if (isEmpty()) {
return null;
}
return head.value;
}
@Override
public T peekLast() {
if (isEmpty()) {
return null;
}
return tail.value;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public int size() {
return size;
}
}

View File

@@ -0,0 +1,39 @@
import java.util.NoSuchElementException;
public class TestDequeue {
public static void main(String[] args) {
// Créer une instance de SimpleQueue
SimpleQueue<Integer> queue = new SimpleQueue<>();
// Tester le comportement de dequeue sur une file vide
System.out.println("Test 1 : Déqueue sur une file vide");
try {
queue.dequeue(); // Doit lever une exception
} catch (NoSuchElementException e) {
System.out.println("Exception levée correctement : " + e.getMessage());
}
// Ajouter des éléments à la file
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
// Tester dequeue pour retirer des éléments dans l'ordre
System.out.println("\nTest 2 : Déqueue sur une file avec des éléments");
System.out.println("Défile : " + queue.dequeue()); // Doit afficher 10
System.out.println("Défile : " + queue.dequeue()); // Doit afficher 20
System.out.println("Défile : " + queue.dequeue()); // Doit afficher 30
// Vérifier que la file est vide après tous les retraits
System.out.println("\nTest 3 : Vérifier si la file est vide après tous les retraits");
System.out.println("La file est vide ? " + queue.isEmpty()); // true
// Retenter dequeue sur une file vide
System.out.println("\nTest 4 : Déqueue sur une file vide après avoir vidé tous les éléments");
try {
queue.dequeue(); // Doit lever une exception
} catch (NoSuchElementException e) {
System.out.println("Exception levée correctement : " + e.getMessage());
}
}
}

View File

@@ -0,0 +1,155 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import java.util.NoSuchElementException;
import java.util.Random;
/**
* Une classe pour faire des tests sur la classe SimpleDeque avec JUnit
* On utilise des String comme type paramétré.
*/
public class TestSimpleDeque {
/**
* On ne peut pas ajouter avec addFirst l'élément null
* [0.5 point]
*/
@Test(expected = NullPointerException.class)
public void addFirstNull() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addFirst(null); // Doit lancer une exception
}
/**
* On ne peut pas ajouter avec addLast l'élément null
* [0.5 point]
*/
@Test(expected = NullPointerException.class)
public void addLastNull() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addLast(null); // Doit lancer une exception
}
/**
* Un deque sans élément est vide.
* [0.5 point]
*/
@Test
public void addNoneIsEmpty() {
MinimalDeque<String> d = new SimpleDeque<>();
assertTrue(d.isEmpty());
}
/**
* Un deque avec 1 élément n'est pas vide.
* [0.5 point]
*/
@Test
public void addOneIsNotEmpty() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addFirst("test");
assertFalse(d.isEmpty());
}
/**
* Ajouter devant et enlever à la fin respecte l'ordre.
* [1 point]
*/
@Test
public void pasDeResquilleur() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addFirst("meu");
d.addFirst("zo");
d.addFirst("bu");
d.addFirst("ga");
assertSame("ga", d.removeLast());
assertSame("bu", d.removeLast());
assertSame("zo", d.removeLast());
assertSame("meu", d.removeLast());
}
/**
* Ajouter derrière et enlever au début respecte l'ordre.
* [1 point]
*/
@Test
public void pasDeResquilleurQuantique() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addLast("ga");
d.addLast("bu");
d.addLast("zo");
d.addLast("meu");
assertSame("ga", d.removeFirst());
assertSame("bu", d.removeFirst());
assertSame("zo", d.removeFirst());
assertSame("meu", d.removeFirst());
}
/**
* On ne peut pas enlever devant un deque vide.
* [1 point]
*/
@Test(expected = NoSuchElementException.class)
public void removeFirstFromEmpty() {
MinimalDeque<String> d = new SimpleDeque<>();
d.removeFirst();
}
/**
* On ne peut pas enlever derrière un deque vide.
* [1 point]
*/
@Test(expected = NoSuchElementException.class)
public void removeLastFromEmpty() {
MinimalDeque<String> d = new SimpleDeque<>();
d.removeLast();
}
/**
* Ajouter et enlever un seul élément dans les deux sens donne le même résultat.
* [2 point]
*/
@Test
public void mangerLaBananeParLesDeuxBouts() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addFirst("ga");
assertSame("ga", d.removeFirst());
d.addLast("ga");
assertSame("ga", d.removeLast());
}
/**
* Invariant de taille
* [4 point]
*/
@Test
public void invariantTaille() {
MinimalDeque<String> d = new SimpleDeque<>();
String[] elements = {"ga", "bu", "zo", "meu"};
Random random = new Random();
int N = random.nextInt(901) + 100;
for (int i = 0; i < N; i++) {
if (random.nextBoolean()) {
d.addFirst(elements[random.nextInt(elements.length)]);
} else {
d.addLast(elements[random.nextInt(elements.length)]);
}
}
for (int i = 0; i < N; i++) {
if (random.nextBoolean()) {
d.removeFirst();
} else {
d.removeLast();
}
}
assertTrue(d.isEmpty());
}
}

View File

@@ -0,0 +1,151 @@
export CLASSPATH=".:/usr/share/java/junit.jar:/usr/share/java/hamcrest-core.jar:$CLASSPATH"
assertThows
assertTrue
assertFalse
assertEquals
assertNotEquals
Voici une réponse détaillée pour chaque question et une explication de ce qu'il faut compléter :
1) [3 points en tout]
a) Quel patron de conception est à l'œuvre ici ?
Réponse :
Le patron de conception utilisé est l'adaptateur (Adapter Pattern). Cette classe agit comme une enveloppe autour d'une implémentation existante de Deque (comme celle dans java.util) pour qu'elle corresponde à l'interface MinimalDeque demandée.
b) Comment fonctionne cette classe ?
Réponse :
La classe SimpleDequeThatsNotCricket délègue toutes ses opérations directement à une instance interne de Deque fournie par java.util. Elle ne réimplémente pas les fonctionnalités mais agit comme une passerelle pour adapter une implémentation existante à une interface spécifique.
2) [-6 à 4 points en tout]
a)
a1) Il est possible de décider si un programme Java va sarrêter quelle que soit son entrée.
Réponse : F (C'est le problème de l'arrêt, qui est indécidable).
a2) Il est possible de décider si un programme C va sarrêter quelle que soit son entrée.
Réponse : F (Même raison que pour Java).
a3) Il est possible de décider si un programme Python ne va pas sarrêter pour certaines entrées.
Réponse : F (Le problème de l'arrêt est indécidable pour tous les langages Turing-complets).
b)
b1) Il est possible de décrire les propriétés souhaitées d'un programme en utilisant des langages de spécifications inspirés de la logique du premier ordre.
Réponse : V
b2) Il existe des logiciels qui, étant donné une spécification et un programme, peuvent décider à coup sûr que le programme satisfait la spécification ou pas.
Réponse : F (C'est une généralisation trop forte, en raison des limitations de la vérification formelle).
b3) Il existe des logiciels qui, étant donné une spécification et un programme, peuvent décider si le programme satisfait la spécification ou pas en demandant à un logiciel d'IA générative (comme ChatGPT) pour générer une preuve.
Réponse : F (Bien que l'IA puisse assister, elle ne garantit pas une vérification formelle).
3) [1 point en tout]
a) Commande pour lancer les tests si junit.jar et hamcrest-core.jar sont dans le même répertoire :
bash
Copier le code
javac -cp .:junit.jar:hamcrest-core.jar TestSimpleDeque.java
java -cp .:junit.jar:hamcrest-core.jar org.junit.runner.JUnitCore TestSimpleDeque
b) Commande pour lancer les tests si les archives sont dans le CLASSPATH :
bash
Copier le code
javac TestSimpleDeque.java
java org.junit.runner.JUnitCore TestSimpleDeque
4) [12 points en tout]
Complétez le fichier TestSimpleDeque.java en fonction des descriptions des tests.
Test addFirstNull:
Ajoutez une assertion pour vérifier qu'une exception est levée. Exemple :
java
Copier le code
@Test(expected = NullPointerException.class)
public void addFirstNull() {
MinimalDeque<String> d = new SimpleDeque<>();
d.addFirst(null);
}
Test addLastNull:
Pareil que pour addFirstNull.
Test addNoneIsEmpty:
Vérifiez qu'un Deque vide est effectivement vide. Exemple :
java
Copier le code
@Test
public void addNoneIsEmpty() {
MinimalDeque<String> d = new SimpleDeque<>();
assertTrue(d.isEmpty());
}
Test addOneIsNotEmpty:
Vérifiez qu'un Deque avec un élément n'est pas vide.
Test pasDeResquilleur:
Ajoutez des éléments devant, enlevez-les derrière, et vérifiez l'ordre.
Test pasDeResquilleurQuantique:
Ajoutez des éléments derrière, enlevez-les devant, et vérifiez l'ordre.
Test removeFirstFromEmpty:
Vérifiez qu'une exception est levée lorsqu'on essaie de retirer un élément d'un Deque vide.
Test removeLastFromEmpty:
Même logique que removeFirstFromEmpty.
Test mangerLaBananeParLesDeuxBouts:
Ajoutez un élément, enlevez-le des deux côtés, et vérifiez.
Test invariantTaille:
Implémentez le test aléatoire avec ajout/suppression jusqu'à ce que le Deque soit vide.
Chain of Responsibility
But : Permet à plusieurs objets de traiter une requête, chaque objet ayant la possibilité de la traiter ou de la transmettre.
Exemple : Système de support technique avec plusieurs niveaux d'escalade.
Command
But : Encapsule une requête en un objet pour paramétrer des actions, les annuler ou les enregistrer.
Exemple : Boutons Annuler/Refaire dans un éditeur de texte.
Interpreter
But : Fournit une représentation grammaticale d'un langage et un interprète pour traiter ses instructions.
Exemple : Interprétation de scripts dans un moteur de jeu.
Iterator
But : Fournit un moyen d'accéder séquentiellement aux éléments d'une collection sans exposer sa représentation.
Exemple : Parcours des éléments d'une liste.
Mediator
But : Définit un objet pour centraliser la communication entre plusieurs objets.
Exemple : Gestionnaire de chat dans une application de messagerie.
Memento
But : Capture l'état interne d'un objet pour pouvoir le restaurer ultérieurement.
Exemple : Sauvegarde dans un jeu vidéo.
Observer
But : Définit une relation 1-n où les objets sont notifiés automatiquement lorsqu'un autre objet change d'état.
Exemple : Notifications pour les abonnés dans un système de messagerie.
State
But : Permet à un objet de changer son comportement lorsqu'il change d'état.
Exemple : Système de verrouillage/déverrouillage dans une application.
Strategy
But : Définit une famille d'algorithmes, les encapsule, et permet de les interchanger dynamiquement.
Exemple : Algorithmes de tri dans une application.
Template Method
But : Définit la structure d'un algorithme tout en laissant certaines étapes spécifiques aux sous-classes.
Exemple : Méthode de rendu dans un moteur de jeu.
Visitor
But : Sépare un algorithme de la structure des objets sur lesquels il opère.
Exemple : Calcul de taxes dans un système de commerce électronique.
java org.junit.runner.JUnitCore TestSimpleDeque
javac -cp .:junit.jar:hamcrest-core.jar TestSimpleDeque.java
java -cp .:junit.jar:hamcrest-core.jar org.junit.runner.JUnitCore TestSimpleDeque
javac TestSimpleDeque.java
java org.junit.runner.JUnitCore TestSimpleDeque

View File

@@ -0,0 +1,69 @@
import java.util.LinkedList;
import java.util.Queue;
public class BullesQueue {
/**
* Effectue un parcours (bulle) dans une file.
*
* @param source La file source contenant les entiers à trier.
* @param destination La file destination pour stocker le résultat du parcours.
* @return true si l'ordre des valeurs a changé, false sinon.
*/
public static boolean bulle(Queue<Integer> source, Queue<Integer> destination) {
boolean changed = false;
if (source.isEmpty()) {
return false;
}
int prev = source.poll(); // Récupère le premier élément
while (!source.isEmpty()) {
int current = source.poll();
if (prev > current) { // Si les éléments ne sont pas dans l'ordre croissant
changed = true;
destination.add(current);
prev = prev; // L'ordre change
} else {
destination.add(prev); // Ajoute directement dans l'ordre
prev = current;
}
}
destination.add(prev); // Ajoute le dernier élément
return changed;
}
/**
* Trie complètement une file d'entiers en utilisant la méthode bulle.
*
* @param file La file d'entiers à trier.
*/
public static void tri(Queue<Integer> file) {
Queue<Integer> intermediaire = new LinkedList<>();
boolean changed;
do {
changed = bulle(file, intermediaire); // Effectue un parcours
// Inverse les files
Queue<Integer> temp = file;
file = intermediaire;
intermediaire = temp;
} while (changed);
// Affiche les valeurs triées
while (!file.isEmpty()) {
System.out.print(file.poll() + " ");
}
System.out.println();
}
public static void main(String[] args) {
// Exemple d'utilisation avec des entiers passés en ligne de commande
Queue<Integer> file = new LinkedList<>();
for (String arg : args) {
file.add(Integer.parseInt(arg));
}
// Trie la file et affiche le résultat
tri(file);
}
}

View File

@@ -0,0 +1,27 @@
public class ExempleQueue {
public static void main(String[] args) {
SimpleQueue<Integer> queue = new SimpleQueue<>();
// Ajouter des éléments à la file
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
// Afficher le premier élément
System.out.println("Premier élément : " + queue.peek()); // 10
// Retirer des éléments
System.out.println("Défile : " + queue.dequeue()); // 10
System.out.println("Défile : " + queue.dequeue()); // 20
// Afficher la taille restante
System.out.println("Taille de la file : " + queue.size()); // 1
// Vérifier si la file est vide
System.out.println("La file est vide ? " + queue.isEmpty()); // false
// Retirer le dernier élément
System.out.println("Défile : " + queue.dequeue()); // 30
System.out.println("La file est vide ? " + queue.isEmpty()); // true
}
}

View File

@@ -0,0 +1,89 @@
import java.util.NoSuchElementException;
public class SimpleQueue<T> {
private static class Node<T> {
T value;
Node<T> next;
Node(T value) {
this.value = value;
}
}
private Node<T> head; // Le début de la file
private Node<T> tail; // La fin de la file
private int size;
public SimpleQueue() {
head = null;
tail = null;
size = 0;
}
/**
* Ajoute un élément à la fin de la file.
*
* @param element L'élément à ajouter.
*/
public void enqueue(T element) {
Node<T> newNode = new Node<>(element);
if (isEmpty()) {
head = tail = newNode;
} else {
tail.next = newNode;
tail = newNode;
}
size++;
}
/**
* Retire et renvoie l'élément en tête de la file.
*
* @return L'élément retiré.
* @throws NoSuchElementException si la file est vide.
*/
public T dequeue() {
if (isEmpty()) {
throw new NoSuchElementException("Queue is empty");
}
T value = head.value;
head = head.next;
if (head == null) { // Si la file est désormais vide
tail = null;
}
size--;
return value;
}
/**
* Renvoie l'élément en tête de la file sans le retirer.
*
* @return L'élément en tête.
* @throws NoSuchElementException si la file est vide.
*/
public T peek() {
if (isEmpty()) {
throw new NoSuchElementException("Queue is empty");
}
return head.value;
}
/**
* Vérifie si la file est vide.
*
* @return true si la file est vide, false sinon.
*/
public boolean isEmpty() {
return size == 0;
}
/**
* Renvoie le nombre d'éléments dans la file.
*
* @return La taille de la file.
*/
public int size() {
return size;
}
}

View File

@@ -0,0 +1,2 @@
/*Felix-vimalaratnam
Patrick*/

Binary file not shown.

15
DEV4.5/Cycle_de_vie/Reticule/.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

3
DEV4.5/Cycle_de_vie/Reticule/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>
</project>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,40 @@
plugins {
alias(libs.plugins.android.application)
}
android {
namespace = "com.example.reticule"
compileSdk = 34
defaultConfig {
applicationId = "com.example.reticule"
minSdk = 19
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}

View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,26 @@
package com.example.reticule;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.reticule", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Reticule"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,15 @@
package com.example.reticule;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ReticleView reticleView = new ReticleView(this, null);
setContentView(reticleView);
}
}

View File

@@ -0,0 +1,89 @@
package com.example.reticule;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.util.TypedValue;
public class ReticleView extends View {
private float reticleX, reticleY;
private final float radius = 50; // Taille du réticule
private float lastTouchX, lastTouchY;
private final Paint paint;
private static final String PREFS_NAME = "ReticlePrefs";
private static final String KEY_X = "reticle_x";
private static final String KEY_Y = "reticle_y";
public ReticleView(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
loadReticlePosition();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(reticleX, reticleY, radius, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float touchX = event.getX();
float touchY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastTouchX = touchX;
lastTouchY = touchY;
break;
case MotionEvent.ACTION_MOVE:
float dx = touchX - lastTouchX;
float dy = touchY - lastTouchY;
if (Math.abs(dx) > dpToPx(10) || Math.abs(dy) > dpToPx(10)) {
reticleX += dx;
reticleY += dy;
lastTouchX = touchX;
lastTouchY = touchY;
invalidate();
}
break;
case MotionEvent.ACTION_UP:
saveReticlePosition();
break;
}
return true;
}
private void saveReticlePosition() {
SharedPreferences prefs = getContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putFloat(KEY_X, reticleX);
editor.putFloat(KEY_Y, reticleY);
editor.apply();
}
private void loadReticlePosition() {
SharedPreferences prefs = getContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
reticleX = prefs.getFloat(KEY_X, getWidth() / 2f);
reticleY = prefs.getFloat(KEY_Y, getHeight() / 2f);
if (reticleX == 0 || reticleY == 0) {
reticleX = getWidth() / 2f;
reticleY = getHeight() / 2f;
}
}
private float dpToPx(float dp) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}
}

View File

@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@@ -0,0 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Reticule" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

Some files were not shown because too many files have changed in this diff Show More