Assessment Generator Updated

Assessment Generator now stores the total correct answers and the total number of answers attempted.
It also displays the final score as a percentage with a maximum of two decimal places.
This commit is contained in:
law39 2020-04-30 14:42:09 +01:00
parent 20d6e5e874
commit 1fc178be0c

View file

@ -7,6 +7,7 @@ import javafx.scene.control.ButtonType;
import uk.ac.aber.cs22120.group20.javafx.*; import uk.ac.aber.cs22120.group20.javafx.*;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.text.DecimalFormat;
import java.util.*; import java.util.*;
@ -22,6 +23,8 @@ public class AssessmentGenerator {
public static boolean isEnglish; public static boolean isEnglish;
static LinkedList<Question> listOfAssessment = new LinkedList<>(); static LinkedList<Question> listOfAssessment = new LinkedList<>();
static int currentAssessment = 0; static int currentAssessment = 0;
static int totalCorrectAnswers = 0;
static int totalAnswers = 0;
/** /**
* Method that will generate a randomized list of questions consisting of random distribution of questions * Method that will generate a randomized list of questions consisting of random distribution of questions
@ -34,6 +37,8 @@ public class AssessmentGenerator {
LinkedList<Question> listOfAssessment = new LinkedList<>(); LinkedList<Question> listOfAssessment = new LinkedList<>();
Random rand = new Random(); Random rand = new Random();
reset();
//int wordToTranslatePlace; //int wordToTranslatePlace;
if (practiseList.size()<5){ if (practiseList.size()<5){
@ -150,7 +155,11 @@ public class AssessmentGenerator {
public static void goToNextQuestion() { public static void goToNextQuestion() {
if (currentAssessment > 0){
Question.showFeedback();
}
if (currentAssessment < 10) { if (currentAssessment < 10) {
Question currentQuestion = listOfAssessment.get(currentAssessment); Question currentQuestion = listOfAssessment.get(currentAssessment);
if (currentQuestion instanceof MatchTheMeaningQuestion) { if (currentQuestion instanceof MatchTheMeaningQuestion) {
@ -166,13 +175,13 @@ public class AssessmentGenerator {
System.err.print("The question has not been recognised"); System.err.print("The question has not been recognised");
System.err.println(currentQuestion); System.err.println(currentQuestion);
} }
currentAssessment++; currentAssessment++;
} else { } else {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("You got ") sb.append("You got ")
.append(Question.correctAnswers / (Question.correctAnswers + Question.wrongAnswers)) .append(new DecimalFormat("#.##").format(((double)(totalCorrectAnswers*100) / (double)totalAnswers)))
.append("%") .append("%")
.append("\n Would you like to test yourself again?"); .append("\n Would you like to test yourself again?");
@ -192,8 +201,8 @@ public class AssessmentGenerator {
Optional<ButtonType> result = alert.showAndWait(); Optional<ButtonType> result = alert.showAndWait();
currentAssessment = 0; currentAssessment = 0;
Question.resetScore();
reset();
if (result.isEmpty() || result.get() == noBtn) { if (result.isEmpty() || result.get() == noBtn) {
ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene); ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene);
} else { } else {
@ -201,4 +210,19 @@ public class AssessmentGenerator {
} }
} }
} }
public static int getTotalCorrectAnswers() {
return totalCorrectAnswers;
}
public static int getTotalAnswers() {
return totalAnswers;
}
public static void reset(){
totalCorrectAnswers = 0;
totalAnswers =0;
LinkedList<Question> listOfAssessment = new LinkedList<>();
currentAssessment = 0;
}
} }