ajout ex2 tp4

This commit is contained in:
Simoes Lukas
2025-09-27 17:38:27 +02:00
parent 3393bcafca
commit 33691f11fb
14 changed files with 171 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package fr.iutfbleau.Quiz;
import java.util.Arrays;
import java.util.Random;
public class SourceQuestions {
public static Question genererQuestion() {
Random r = new Random();
int x = r.nextInt(11);
int y = r.nextInt(11);
String intitule = x + " x " + y + " = ?";
int bonneReponse = x*y;
int[] mauvaisesReponses = new int[4];
for (int i = 0; i != mauvaisesReponses.length; i++) {
mauvaisesReponses[i] = r.nextInt(101);
}
int indexBonneReponse = r.nextInt(4);
String[] options = new String[4];
options[indexBonneReponse] = "" + bonneReponse;
for (int i = 0; i != 4; i++) {
if (i != indexBonneReponse) {
options[i] = "" + mauvaisesReponses[i];
}
}
return new Question(intitule, options, indexBonneReponse);
}
}