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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package kahootgui;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.text.Text;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Controller {
@FXML
private ToggleGroup answers;
@FXML
private Text question_text;
@FXML
private RadioButton radio_btn_1;
@FXML
private RadioButton radio_btn_2;
@FXML
private RadioButton radio_btn_3;
@FXML
private RadioButton radio_btn_4;
@FXML
private Button answerBtn;
private final Questions[] questions = new Questions[] {
new Questions("В каком из вариантов представлен корректный формат вывода информации на экран?", new String[] {"Console.Write()", "console.log()", "print()", "System.out.println()"}),
new Questions("Какой тип данных отвечает за целые числа?", new String[] {"String", "Float", "Boolean", "Integer"}),
new Questions("Где правильно присвоено новое значение к многомерному массиву?", new String[] {"a(0)(0) = 1;", "a[0 0] = 1;", "a{0}{0} = 1;", "a[0][0] = 1;"}),
new Questions("Какой метод позволяет запустить программу на Java?", new String[] {"Основного метода нет", "С класса, что был написан первым и с методов что есть внутри него", "Любой, его можно задавать в настройках проекта", "С метода main в любом из классов"}),
new Questions("Каждый файл должен называется...", new String[] {"по имени первой библиотеки в нём", "по имени названия пакета", "как вам захочется", "по имени класса в нём"}),
new Questions("Сколько параметров может принимать функция?", new String[] {"5", "10", "20", "неограниченное количество"})
};
private int nowQuestion = 0, correctAnswers;
private String nowCorrectAnswer;
@FXML
public void initialize() {
nowCorrectAnswer = questions[nowQuestion].correctAnswer();
answerBtn.setOnAction(e -> {
RadioButton selectedRadioButton = (RadioButton) answers.getSelectedToggle();
if(selectedRadioButton != null) {
String toogleGroupValue = selectedRadioButton.getText();
if(toogleGroupValue.equals(nowCorrectAnswer)) {
System.out.println("Верный ответ");
correctAnswers++;
} else {
System.out.println("Не верный ответ");
}
// Это был последний вопрос
if(nowQuestion + 1 == questions.length) {
radio_btn_1.setVisible(false);
radio_btn_2.setVisible(false);
radio_btn_3.setVisible(false);
radio_btn_4.setVisible(false);
answerBtn.setVisible(false);
question_text.setText("Вы ответили корректно на " + correctAnswers + " из " + questions.length + " вопросов!");
} else {
nowQuestion++;
nowCorrectAnswer = questions[nowQuestion].correctAnswer();
question_text.setText(questions[nowQuestion].getQuestion());
String[] answers = questions[nowQuestion].getAnswers();
List<String> intList = Arrays.asList(answers);
Collections.shuffle(intList);
radio_btn_1.setText(intList.get(0));
radio_btn_2.setText(intList.get(1));
radio_btn_3.setText(intList.get(2));
radio_btn_4.setText(intList.get(3));
selectedRadioButton.setSelected(false);
}
}
});
}
}
|