ajout ex2 tp4
This commit is contained in:
39
DEV3.1/TP04/02_Quiz/src/SourceQuestions.java
Normal file
39
DEV3.1/TP04/02_Quiz/src/SourceQuestions.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user