-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuestionsGeneratorCapitales.java
48 lines (39 loc) · 1.42 KB
/
QuestionsGeneratorCapitales.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.teacher.quiz.generatorQuestions;
import java.util.ArrayList;
import java.util.Random;
import com.teacher.quiz.Question;
import com.teacher.quiz.Quizz;
public class QuestionsGeneratorCapitales extends QuestionsGenerator {
private int index;
public QuestionsGeneratorCapitales(Quizz quizz) {
super(quizz);
}
@Override
public ArrayList<Question> generateAllQuestions(int numberQuestions, Quizz quizz) {
String[][] data = getData();
ArrayList<Question> allQuestions = new ArrayList<Question>();
if (numberQuestions > data.length) {
setHasPlayed(false);
quizz.displayMessage(String.format("Il n'y a que %s questions disponibles...", data.length));
} else {
setHasPlayed(true);
ArrayList<Integer> arrayOfIndex = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < numberQuestions; i++) {
do {
index = random.nextInt(data.length);
} while (arrayOfIndex.contains(index));
arrayOfIndex.add(index);
String pays = data[index][0];
String capitale = data[index][1];
Question question = new Question(String.format("Quelle est la capitale de ce pays %s ?", pays), capitale);
allQuestions.add(question);
}
}
return allQuestions;
}
public String[][] getData() {
String[][] data = { { "France", "Paris" }, { "Allemagne", "Berlin" }, { "Colombie", "Bogota" }, { "Japon", "Tokyo" } };
return data;
}
}