From 909a8125a510ea4666178c89396f7f2f299e92f5 Mon Sep 17 00:00:00 2001 From: EmmanuelTiamzon Date: Fri, 7 Nov 2025 16:00:23 +0100 Subject: [PATCH] exo1 TP generecite --- .../TP4/ex2Quiz/src/Modele/Questionnaire.java | 22 ++++++--- DEV.3.2/TP/TP1-Generecite/Listes.class | Bin 0 -> 1532 bytes DEV.3.2/TP/TP1-Generecite/Listes.java | 46 ++++++++++++++++++ DEV.3.2/cours/test.md | 0 4 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 DEV.3.2/TP/TP1-Generecite/Listes.class create mode 100644 DEV.3.2/TP/TP1-Generecite/Listes.java create mode 100644 DEV.3.2/cours/test.md diff --git a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java index b305870..e716955 100644 --- a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java +++ b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java @@ -27,12 +27,20 @@ public class Questionnaire { this.choixUtilisateur = new ChoixUtilisateur(nombreQuestions); } + public Questionnaire(int choixUtilisateur, int nombreQuestions) { + this.questions = new Question[nombreQuestions]; + for (int i = 0; i < nombreQuestions; i++) { + this.questions[i] = new Question(); + } + this.choixUtilisateur = new ChoixUtilisateur(choixUtilisateur); + } + /** * Getter pour le tableau des questions * @return le tableau des questions */ public Question[] getQuestions() { - return questions; + return this.questions; } /** @@ -41,7 +49,7 @@ public class Questionnaire { * @return la question a l'index donnee */ public Question getQuestion(int index) { - return questions[index]; + return this.questions[index]; } /** @@ -49,7 +57,7 @@ public class Questionnaire { * @return les choix de l'utilisateur */ public ChoixUtilisateur getChoixUtilisateur() { - return choixUtilisateur; + return this.choixUtilisateur; } /** @@ -57,7 +65,7 @@ public class Questionnaire { * @return le nombre de questions dans le questionnaire */ public int getNombreQuestions() { - return questions.length; + return this.questions.length; } /** @@ -66,9 +74,9 @@ public class Questionnaire { */ public int calculerScore() { int score = 0; - for (int i = 0; i < questions.length; i++) { - int choix = choixUtilisateur.getChoix(i); - if (choix == questions[i].getCorrectIndex()) { + for (int i = 0; i < this.questions.length; i++) { + int choix = this.choixUtilisateur.getChoix(i); + if (choix == this.questions[i].getCorrectIndex()) { score++; } } diff --git a/DEV.3.2/TP/TP1-Generecite/Listes.class b/DEV.3.2/TP/TP1-Generecite/Listes.class new file mode 100644 index 0000000000000000000000000000000000000000..d041d705d56f5689eebcde09f2a91517adf1173f GIT binary patch literal 1532 zcmX^0Z`VEs1_mdFC@uyj24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc24S$G(vr*^eaE7r#7dvc;u0}82LrK$dDj0|ELo|--wDy%^U3Gy%qF$gmzIwOOyh8MDKkf1dugA#)>JA(=jgDQg>N`M7d7MG;vGBPmdmzFRx zh(a8lnXeyEl$lo&TvC*pm}||&puwQY&Y%UdQ5#ivNl_-qPBm=4g_s2n$zZTLYas>( z23;NoJqCS72Jzg)>{RFcyyV1^@XV47=ls0llEl1{VnzlO!=O5meFPQaVlZSdVrMYs zVK8AZg~czb%NZHi3qbzJ$wP|}s1cfBLJW)yxkK zWRQgV3!H46^K)`ilS?x5^Q<+agcz6^blDl~7#Y|=DJiv>k%7fIKP8osf!`-HFV(L! zHz~C!Brz!`m63rZH!(90ly;&qgG4iok%22XzqBYh)h!dGm>Xi89w=HF83dg2^Gk|L ziV_QaQ%f@PQ;Inl+!-0Tb25udQa$rZtP~hI7(5vnc)`-?%5 z!IpsuoIRNs7(rzc10#by0|SFB10w??0|NuA)^-NQjSLJ7j0_G83=C{wL1qR{21f=b zsM044%nU3H3=C6tGq6W)XW;aK(!NmIPg{U%2LsnO27z!LA(0&nq9B$oTuc`sCc+@K zgFyx)y@^3ldk2I1E(RS2hHVT6n-~;zz+5vJR~O7R2Xl3`w=r0R>*|2WO$>? listeInt = new ArrayList<>(); + ArrayList listeFloat = new ArrayList<>(); + ArrayList listeNumber = new ArrayList<>(); + + // On ajoute des éléments maintenant + listeInt.add(10); + listeFloat.add(3.14f); + listeNumber.add(10); // Faisable (Integer herite de Number) + listeNumber.add(3.14f); // Faisable (Float herite de Number) + listeNumber.add(5L); // Faisable (Long herite de Number) + + + // Affichage + System.out.println("listeInt: " + listeInt); + System.out.println("listeFloat: " + listeFloat); + System.out.println("listeNumber: " + listeNumber); + + /* + * Ce qui nous renvoie : + * listeInt: [10] + * listeFloat: [3.14] + * listeNumber: [10, 3.14, 5] + */ + + // Test addAll + listeNumber.addAll(listeInt); // OK + listeNumber.addAll(listeFloat); // OK + System.out.println("listeNumber après addAll: " + listeNumber); + + // listeInt.addAll(listeNumber); // ERREUR + + } +} + +/* + +On conclut que +ArrayList -> accepte seulement des Integer +ArrayList -> accepte seulement des Float +ArrayList -> accepte tous les types numériques (Integer, Float, Long, Double, etc... car ils heritent de la classe Number) + + */ \ No newline at end of file diff --git a/DEV.3.2/cours/test.md b/DEV.3.2/cours/test.md new file mode 100644 index 0000000..e69de29