exo1 TP generecite

This commit is contained in:
EmmanuelTiamzon
2025-11-07 16:00:23 +01:00
parent 6b60c121aa
commit 909a8125a5
4 changed files with 61 additions and 7 deletions

View File

@@ -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++;
}
}