Files
DEV/DEV3.1/TP04/02_Quiz/src/SourceQuestions.java

39 lines
765 B
Java
Raw Normal View History

2025-09-27 17:38:27 +02:00
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);
}
}