Конструктор текстовых тестов(с функцией тестирования)
Текстовый тест это тест без всяческих изображений, схем или диаграмм. Просто задаются вопросы с пронумерованными вариантами ответов и пользователь выбирает номер верного по его мнению ответа.
@FXML
private void nextQuestionAction(ActionEvent event) {
if("".equals(t.getText())){
alertWindow("", "Введите вопрос и варианты ответа", "Ошибка");
return;
}
if("".equals(cb.getValue())){
alertWindow("", "Выберите вариант ответа", "Ошибка");
return;
}
if(r==1){
recordInFile(cb.getValue(),testPath+System.getProperty(separator)+"ответы1", true);
recordInFile(t.getText(),testPath+System.getProperty(separator)+volumeAnswers("ответы1"),false);
l3.setText("Вопрос №"+volumeAnswers("ответы1")+" сохранен");
t.setText("");
cb.setValue("");
}else{
calc++;
if(calc==volumeAnswers("ответы1")){
b.setText("результат");
}
if(calc>volumeAnswers("ответы1")){
calc=0;
recordInFile(cb.getValue(),testPath+System.getProperty(separator)+"ответы2", true);
recordInFile("\n"+dayDateAndTime()+"\n"+userName()+"\n"+resultsTest(),testPath+
System.getProperty(separator)+"результаты", true);
showMessage(resultsTest(),"Тест завершен","Результат");
recordInFile("",testPath+System.getProperty(separator)+"ответы2", false);
cleanAll();
b.setText("следующий вопрос");
b.setDisable(true);
t.setEditable(false);
return;
}
t.setText(readerFile(testPath+System.getProperty(separator)+calc));
recordInFile(cb.getValue(),testPath+System.getProperty(separator)+"ответы2", true);
l3.setText("Вопрос № "+calc+". Осталось вопросов: "+(volumeAnswers("ответы1")-calc));
cb.setValue("");
}
}
@FXML
private void openItem(ActionEvent event){
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("Открытие теста");
dc.setInitialDirectory(new File(path));
|
|
File file = dc.showDialog(null);
if(file!=null){
testPath=file.getAbsolutePath();
if(!new File(testPath+System.getProperty(separator)+"ответы1").exists()){
alertWindow("", "Тест "+file.getName()+" пока пустой.Дополните его", "Внимание!");
return;
}
if(volumeAnswers("ответы2")!=0){
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("ВНИМАНИЕ!");
alert.setHeaderText("Тест не пройден!");
alert.setContentText("Хотите продолжить?");
Optional<ButtonType> resultAlert = alert.showAndWait();
if (resultAlert.get() == ButtonType.OK){
t.setText(readerFile(testPath+System.getProperty(separator)+(volumeAnswers("ответы2")+1)));
l3.setText("Вопрос № "+(volumeAnswers("ответы2")+1)+". Осталось вопросов: "+(volumeAnswers("ответы1")-volumeAnswers("ответы2")-1));
l1.setText(file.getName());
l2.setText("тестирование");
if((volumeAnswers("ответы1")-volumeAnswers("ответы2")-1)==0){
b.setText("результат");
}else{
b.setText("следующий вопрос");
}
b.setDisable(false);
t.setEditable(false);
calc=volumeAnswers("ответы2")+1;
r=0;
return;
}
}
t.setText(readerFile(testPath+System.getProperty(separator)+"1"));
recordInFile("",testPath+System.getProperty(separator)+"ответы2", false);
l3.setText("Вопрос № 1. Осталось вопросов: "+(volumeAnswers("ответы1")-1));
l1.setText(file.getName());
l2.setText("тестирование");
if((volumeAnswers("ответы1")-1)==0){
b.setText("результат");
}else{
b.setText("следующий вопрос");
}
b.setDisable(false);
t.setEditable(false);
calc=1;
r=0;
}
}
@FXML
|
|
private void createItem(ActionEvent event){
TextInputDialog dialog = new TextInputDialog("тест "+new Random().nextInt(10000));
dialog.setTitle("Создание теста");
dialog.setHeaderText("Введите название нового теста");
dialog.setContentText("Название теста:");
Optional<String> name = dialog.showAndWait();
if(name.isPresent()&&!"".equals(name.get())){
testPath=path+System.getProperty(separator)+name.get();
File f=new File(testPath);
if(f.exists()){
alertWindow("", "Тест с таким названием уже имеется\nВыберите другое название", "Ошибка");
return;
}else{
f.mkdir();
}
l1.setText(f.getName());
l2.setText("конструирование");
l3.setText("");
b.setText("следующий вопрос");
b.setDisable(false);
t.setEditable(true);
t.setText("");
r=1;
}
}
Дата добавления: 2019-02-12; просмотров: 127; Мы поможем в написании вашей работы! |
Мы поможем в написании ваших работ!