diff --git a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/ChoixUtilisateur.java b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/ChoixUtilisateur.java
new file mode 100644
index 0000000..d68d767
--- /dev/null
+++ b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/ChoixUtilisateur.java
@@ -0,0 +1,41 @@
+package Modele;
+
+/**
+ * la classe ChoixUtilisateur
permet de stocker les choix de l'utilisateur pour chaque question.
+ */
+public class ChoixUtilisateur {
+
+ /**
+ * Le tableau des choix de l'utilisateur pour chaque question. -1 signifie pas encore repondu
+ */
+ private int[] choix;
+
+ /**
+ * Constructeur de la classe ChoixUtilisateur
+ * @param nombreQuestions le nombre de questions dans le questionnaire
+ */
+ public ChoixUtilisateur(int nombreQuestions) {
+ this.choix = new int[nombreQuestions]; // -1 signifie pas encore repondu
+ for (int i = 0; i < nombreQuestions; i++) {
+ this.choix[i] = -1;
+ }
+ }
+
+ /**
+ * Setter pour un choix de reponse a une question
+ * @param questionIndex l'index de la question
+ * @param reponseIndex l'index de la reponse choisie par l'utilisateur
+ */
+ public void setChoix(int questionIndex, int reponseIndex) {
+ this.choix[questionIndex] = reponseIndex;
+ }
+
+ /**
+ * Getter pour un choix de reponse a une question
+ * @param questionIndex l'index de la question
+ * @return l'index de la reponse choisie par l'utilisateur
+ */
+ public int getChoix(int questionIndex) {
+ return this.choix[questionIndex];
+ }
+}
\ No newline at end of file
diff --git a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Question.java b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Question.java
index 821a6fb..3183929 100644
--- a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Question.java
+++ b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Question.java
@@ -1,14 +1,172 @@
+package Modele;
+
+import java.util.Random;
+
+/**
+ * la classe Question
permet de generer une question aleatoire
+ * avec deux operandes et une operation parmi +,-,x,/
+ * Elle genere egalement 4 propositions de reponses dont une est correcte et une est fausse
+ *
+ * @version 1.0
+ * @author Emmanuel TIAMZON
+ */
public class Question {
- private String[] operation;
- private int operand;
+ /**
+ * Les attributs de la classe Question
+ */
+ private String[] operations;
+
+ /**
+ * operation courante parmi +,-,x,/
+ */
+ private String operation;
+ /**
+ * L'operande A de la question
+ */
+ private int operandA;
+
+ /**
+ * l'operande B de la question
+ */
+ private int operandB;
+
+ /**
+ * Constante Random pour la generation aleatoire
+ */
+ private Random rand;
+
+ /**
+ * La reponse correcte de la question
+ */
+ private int answer;
+
+ /**
+ * La question sous forme de chaine de caracteres
+ */
+ private String questionString;
+
+ /**
+ * Propositions de reponses (4 au total, une correcte et trois fausses)
+ */
+ private String[] propositions;
+
+ /**
+ * Index de la reponse correcte dans le tableau des propositions
+ */
+ private int correctIndex;
+
+ /**
+ * Constructeur de la classe Question
+ */
public Question() {
- this.operation[] = {" + "," - "," x "," / "};
+ this.operations = new String[] {"+","-","x","/"};
+ this.rand = new Random();
+ int opIndex = rand.nextInt(this.operations.length);
+ this.operation = this.operations[opIndex];
+
+ this.operandA = rand.nextInt(10) + 1;
+ this.operandB = rand.nextInt(10) + 1;
+ if (this.operation.equals("/")) {
+ this.operandB = rand.nextInt(9) + 1; // S'assure que b n'est pas 0
+ this.operandA = this.operandB * (rand.nextInt(10) + 1); // S'assure que a est un multiple de b
+ }
+ this.answer = computeAnswer();
+
+ this.propositions = new String[4]; // 4 propositions pour chaque question
+ this.correctIndex = rand.nextInt(4);
+ for (int i = 0; i < 4; i++) {
+ if (i == correctIndex) {
+ propositions[i] = String.valueOf(answer);
+ } else {
+ int fake;
+ do {
+ fake = answer + rand.nextInt(21) - 10;
+ } while (fake == answer || fake < 0 || contains(propositions, String.valueOf(fake)));
+ propositions[i] = String.valueOf(fake);
+ }
+ }
}
- public int choixOperand() {
- System.out.println("coucou manu");
- return this.operand;
+
+ /**
+ * Genere une nouvelle question sous forme de chaine de caracteres
+ * @return la question sous forme de chaine de caracteres
+ */
+ public String makeNewQuestion() {
+ this.questionString = "What is " + this.operandA + this.operation + this.operandB + " ?";
+ return questionString;
+ }
+
+ /**
+ * Verifie si un tableau de chaines de caracteres contient une valeur donnee
+ * @param arr array de chaines de caracteres
+ * @param val valeur a chercher
+ * @return true si le tableau contient la valeur, false sinon
+ */
+ private boolean contains(String[] arr, String val) {
+ for (String s : arr) {
+ if (val != null && val.equals(s)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Calcule la reponse de la question courante
+ * @return la reponse de la question courante
+ */
+ public int computeAnswer() {
+ switch (this.operation) {
+ case "+":
+ return this.operandA + this.operandB;
+ case "-":
+ return this.operandA - this.operandB;
+ case "x":
+ return this.operandA * this.operandB;
+ case "/":
+ return this.operandA / this.operandB;
+ default:
+ return 0;
+ }
+ }
+
+ /**
+ * Affiche les choix d'operations disponibles
+ */
+ public void choixOperation() {
+ System.out.println("Choose an operation between 1 and 4: \n 1. + \n 2. - \n 3. x \n 4. /");
+ }
+
+ /**
+ * Getter pour la question sous forme de chaine de caracteres
+ * @return la question sous forme de chaine de caracteres
+ */
+ public String getQuestionString() {
+ return this.questionString;
+ }
+
+ /**
+ * Getter pour l'operation courante
+ * @return l'operation courante
+ */
+ public String getOperation() {
+ return this.operation;
+ }
+
+ /**
+ * Getter pour les propositions de reponses
+ * @return les propositions de reponses
+ */
+ public String[] getPropositions() {
+ return propositions;
+ }
+
+ /**
+ * Getter pour l'index de la reponse correcte
+ * @return l'index de la reponse correcte
+ */
+ public int getCorrectIndex() {
+ return correctIndex;
}
}
\ No newline at end of file
diff --git a/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java
new file mode 100644
index 0000000..b305870
--- /dev/null
+++ b/DEV.3.1/TP/TP4/ex2Quiz/src/Modele/Questionnaire.java
@@ -0,0 +1,77 @@
+package Modele;
+
+/**
+ * la classe Questionnaire
permet de representer un questionnaire compose de plusieurs questions.
+ */
+public class Questionnaire {
+
+ /**
+ * Le tableau des questions du questionnaire.
+ */
+ private Question[] questions;
+
+ /**
+ * Les choix de l'utilisateur pour chaque question.
+ */
+ private ChoixUtilisateur choixUtilisateur;
+
+ /**
+ * Constructeur de la classe Questionnaire
+ * @param nombreQuestions le nombre de questions dans le questionnaire
+ */
+ public Questionnaire(int nombreQuestions) {
+ this.questions = new Question[nombreQuestions];
+ for (int i = 0; i < nombreQuestions; i++) {
+ this.questions[i] = new Question();
+ }
+ this.choixUtilisateur = new ChoixUtilisateur(nombreQuestions);
+ }
+
+ /**
+ * Getter pour le tableau des questions
+ * @return le tableau des questions
+ */
+ public Question[] getQuestions() {
+ return questions;
+ }
+
+ /**
+ * Getter pour une question a un index donnee
+ * @param index l'index de la question
+ * @return la question a l'index donnee
+ */
+ public Question getQuestion(int index) {
+ return questions[index];
+ }
+
+ /**
+ * Getter pour les choix de l'utilisateur
+ * @return les choix de l'utilisateur
+ */
+ public ChoixUtilisateur getChoixUtilisateur() {
+ return choixUtilisateur;
+ }
+
+ /**
+ * Getter pour le nombre de questions dans le questionnaire
+ * @return le nombre de questions dans le questionnaire
+ */
+ public int getNombreQuestions() {
+ return questions.length;
+ }
+
+ /**
+ * Calcule le nombre de bonnes réponses de l'utilisateur.
+ * @return le score (nombre de bonnes réponses)
+ */
+ public int calculerScore() {
+ int score = 0;
+ for (int i = 0; i < questions.length; i++) {
+ int choix = choixUtilisateur.getChoix(i);
+ if (choix == questions[i].getCorrectIndex()) {
+ score++;
+ }
+ }
+ return score;
+ }
+}
\ No newline at end of file
diff --git a/DEV.3.1/TP/TP4/ex2Quiz/src/Vue/AffichageQuestion.java b/DEV.3.1/TP/TP4/ex2Quiz/src/Vue/AffichageQuestion.java
new file mode 100644
index 0000000..d628336
--- /dev/null
+++ b/DEV.3.1/TP/TP4/ex2Quiz/src/Vue/AffichageQuestion.java
@@ -0,0 +1,17 @@
+/**
+ * Classe pour l'affichage des questions
+ */
+public class AffichageQuestion {
+
+ /**
+ * Mode solution activé ou non (false si mode questionnaire, true si mode solution)
+ */
+ private boolean modeSolution;
+
+ /**
+ * Constructeur de la classe AffichageQuestion
+ */
+ public AffichageQuestion() {
+ this.modeSolution = false;
+ }
+}
\ No newline at end of file