diff options
Diffstat (limited to 'src/main/java/kahootgui')
| -rw-r--r-- | src/main/java/kahootgui/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | src/main/java/kahootgui/App.java | 25 | ||||
| -rw-r--r-- | src/main/java/kahootgui/Controller.java | 97 | ||||
| -rw-r--r-- | src/main/java/kahootgui/Main.java | 9 | ||||
| -rw-r--r-- | src/main/java/kahootgui/Questions.java | 25 | 
5 files changed, 156 insertions, 0 deletions
diff --git a/src/main/java/kahootgui/.DS_Store b/src/main/java/kahootgui/.DS_Store Binary files differnew file mode 100644 index 0000000..09747aa --- /dev/null +++ b/src/main/java/kahootgui/.DS_Store diff --git a/src/main/java/kahootgui/App.java b/src/main/java/kahootgui/App.java new file mode 100644 index 0000000..5dae92b --- /dev/null +++ b/src/main/java/kahootgui/App.java @@ -0,0 +1,25 @@ +package kahootgui; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.util.Objects; + +public class App extends Application { + +    @Override +    public void start(Stage primaryStage) throws Exception { +        Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("main.fxml"))); +        primaryStage.setTitle("Тесты по языка программирования"); +        primaryStage.setScene(new Scene(root, 747, 460)); +        primaryStage.show(); +    } + +    public static void main(String[] args) { +        launch(args); +    } + +} diff --git a/src/main/java/kahootgui/Controller.java b/src/main/java/kahootgui/Controller.java new file mode 100644 index 0000000..476f9f1 --- /dev/null +++ b/src/main/java/kahootgui/Controller.java @@ -0,0 +1,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); +                } + +            } +        }); +    } + +} diff --git a/src/main/java/kahootgui/Main.java b/src/main/java/kahootgui/Main.java new file mode 100644 index 0000000..bbcccb1 --- /dev/null +++ b/src/main/java/kahootgui/Main.java @@ -0,0 +1,9 @@ +package kahootgui; + +public class Main { + +    public static void main(String[] args) { +        App.main(args); +    } + +} diff --git a/src/main/java/kahootgui/Questions.java b/src/main/java/kahootgui/Questions.java new file mode 100644 index 0000000..44bbe34 --- /dev/null +++ b/src/main/java/kahootgui/Questions.java @@ -0,0 +1,25 @@ +package kahootgui; + +public class Questions { + +    private String question; +    private String[] answers; + +    public Questions(String question, String[] answers) { +        this.question = question; +        this.answers = answers; +    } + +    public String correctAnswer() { +        return this.answers[answers.length - 1]; +    } + +    public String getQuestion() { +        return question; +    } + +    public String[] getAnswers() { +        return answers; +    } + +}  |