Updated Assessment generator
Assessment generator now uses practice list passed to it. Added message box at end of assessment giving a score and asking if the user wants to retry. Updated FlashcardController to pass the practice list to the assessment generator
This commit is contained in:
parent
d8808a3b9e
commit
1858c23217
3 changed files with 149 additions and 112 deletions
|
@ -109,7 +109,7 @@ public class FlashcardController {
|
|||
|
||||
@FXML
|
||||
private void switchToAddWord() throws IOException {
|
||||
AssessmentGenerator.generateAssessment(Application.dictionary);
|
||||
AssessmentGenerator.generateAssessment(Application.practiseList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package uk.ac.aber.cs22120.group20.selfassessment;
|
||||
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import uk.ac.aber.cs22120.group20.javafx.Application;
|
||||
import uk.ac.aber.cs22120.group20.javafx.ScreenSwitch;
|
||||
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Class that contains methods to create a randomised list of questions that will
|
||||
* contain a random distribution of question types.
|
||||
*
|
||||
* @Author
|
||||
* @Version
|
||||
* @See
|
||||
|
@ -25,16 +27,14 @@ public class AssessmentGenerator {
|
|||
/**
|
||||
* Method that will generate a randomized list of questions consisting of random distribution of questions
|
||||
* types, using the dictionary’s practice words as the parameter.
|
||||
*
|
||||
* @param wordList
|
||||
* @return
|
||||
*/
|
||||
public static LinkedList<Question> generateAssessment(LinkedList<DictionaryEntry> wordList){
|
||||
public static LinkedList<Question> generateAssessment(LinkedList<DictionaryEntry> practiseList) {
|
||||
LinkedList<Question> listOfAssessment = new LinkedList<>();
|
||||
LinkedList<DictionaryEntry> practiseList = Application.practiseList;
|
||||
Random rand = new Random();
|
||||
|
||||
|
||||
|
||||
//int wordToTranslatePlace;
|
||||
|
||||
for (int numberToGenerate = 0; numberToGenerate < 10; numberToGenerate++) {
|
||||
|
@ -75,6 +75,7 @@ public class AssessmentGenerator {
|
|||
* Method
|
||||
* that will generate a list of questions that are the type ‘Match The Meanings’, using the dictionary's
|
||||
* practice words as the parameter.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Question generateMatchMeaning(LinkedList<DictionaryEntry> practiceList) {
|
||||
|
@ -84,7 +85,7 @@ public class AssessmentGenerator {
|
|||
int successfulAnswersSelected = 0;
|
||||
while (successfulAnswersSelected < 4) {
|
||||
DictionaryEntry selectedAnswer;
|
||||
selectedAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
|
||||
selectedAnswer = practiceList.get(rand.nextInt(practiceList.size()));
|
||||
if (answerList.contains(selectedAnswer)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -100,13 +101,14 @@ public class AssessmentGenerator {
|
|||
* Method
|
||||
* that will generate a list of questions that are the type ‘6 Meanings’, using the dictionary's practice
|
||||
* words as the parameter.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Question generateSixMeanings(LinkedList<DictionaryEntry> practiseList) {
|
||||
Question returnValue;
|
||||
ArrayList<DictionaryEntry> listOfAnswers = new ArrayList<>();
|
||||
Random rand = new Random();
|
||||
DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size() - 1));
|
||||
DictionaryEntry wordToTranslate = practiseList.get(rand.nextInt(practiseList.size()));
|
||||
SixMeaningsQuestion generatedQuestion = new SixMeaningsQuestion(wordToTranslate, Application.dictionary);
|
||||
return generatedQuestion;
|
||||
}
|
||||
|
@ -115,19 +117,20 @@ public class AssessmentGenerator {
|
|||
* Method that
|
||||
* will generate a list of questions that are the type ‘Translation’, using the dictionary's practice words as
|
||||
* the parameter.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Question generateTranslationTest(LinkedList<DictionaryEntry> practiceList) {
|
||||
Random rand = new Random();
|
||||
DictionaryEntry selectedCorrectAnswer;
|
||||
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()-1));
|
||||
selectedCorrectAnswer = practiceList.get(rand.nextInt(practiceList.size()));
|
||||
Question generatedQuestion = new TranslationQuestion(selectedCorrectAnswer);
|
||||
return generatedQuestion;
|
||||
}
|
||||
|
||||
|
||||
public static void goToNextQuestion() {
|
||||
|
||||
if (currentAssessment < 10) {
|
||||
Question currentQuestion = listOfAssessment.get(currentAssessment);
|
||||
|
||||
if (currentQuestion instanceof MatchTheMeaningQuestion) {
|
||||
|
@ -145,6 +148,35 @@ public class AssessmentGenerator {
|
|||
}
|
||||
|
||||
currentAssessment++;
|
||||
} else {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("You scored: ")
|
||||
.append(Question.correctAnswers).append("/")
|
||||
.append(Question.correctAnswers + Question.wrongAnswers)
|
||||
.append("\n Would you like to test yourself again?");
|
||||
|
||||
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
alert.setTitle("You finished the tests");
|
||||
alert.setHeaderText("You finished the tests\n Well Done!");
|
||||
alert.setResizable(false);
|
||||
alert.setContentText(sb.toString());
|
||||
Optional<ButtonType> result = alert.showAndWait();
|
||||
((Button) alert.getDialogPane().lookupButton(ButtonType.OK)).setText("Yes");
|
||||
((Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL)).setText("No");
|
||||
|
||||
if (result.isEmpty() || result.get() == ButtonType.CANCEL) {
|
||||
currentAssessment=0;
|
||||
Question.resetScore();
|
||||
ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene);
|
||||
|
||||
} else {
|
||||
currentAssessment = 0;
|
||||
Question.resetScore();
|
||||
generateAssessment(Application.practiseList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,11 @@ public class Question {
|
|||
}else wrongAnswers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetScore(){
|
||||
correctAnswers = 0;
|
||||
wrongAnswers =0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue