Question Class Updated

Question Class now handles a dialogue box containing the User's feedback much better.
Now provides a breakdown of each question and which the user got correct.
This commit is contained in:
law39 2020-04-30 14:34:24 +01:00
parent 366c10984b
commit 03e2a824bc

View file

@ -2,6 +2,7 @@ package uk.ac.aber.cs22120.group20.selfassessment;
import javafx.scene.control.Alert;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.util.ArrayList;
@ -19,6 +20,7 @@ public class Question {
public static int correctAnswers = 0;
public static int wrongAnswers =0;
public static StringBuilder sb = new StringBuilder();
/**
*
@ -27,48 +29,69 @@ public class Question {
* @param isEnglish
*/
public static void checkAnswer(ArrayList<DictionaryEntry> listOfCorrectQuestions, ArrayList<String>listOfAnswers, boolean isEnglish){
StringBuilder sb;
if(isEnglish){
for(int i=0; i<listOfCorrectQuestions.size();i++){
sb = new StringBuilder();
sb.append(listOfAnswers.get(i)).append(" is the Welsh for ").append(listOfCorrectQuestions.get(i).getEnglish());
sb
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
.append(" is the English for ")
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
.append(". ");
if(listOfCorrectQuestions.get(i).getWelsh().equals(listOfAnswers.get(i))){
sb.append("Correct!");
correctAnswers++;
feedbackAnswer(sb.toString(), true);
}else{
sb.append("'").append(listOfAnswers.get(i)).append("'").append(" is incorrect.");
wrongAnswers++;
feedbackAnswer(sb.toString(), false);
}
sb.append("\n");
}
}else{
for(int i=0; i<listOfCorrectQuestions.size();i++){
sb = new StringBuilder();
sb.append(listOfAnswers.get(i)).append(" is the English for ").append(listOfCorrectQuestions.get(i).getWelsh());
sb
.append("'").append(listOfCorrectQuestions.get(i).getEnglish()).append("'")
.append(" is the English for ")
.append("'").append(listOfCorrectQuestions.get(i).getWelsh()).append("'")
.append(". ");
if(listOfCorrectQuestions.get(i).getEnglish().equals(listOfAnswers.get(i))){
sb.append("Correct!");
correctAnswers++;
feedbackAnswer(sb.toString(), true);
}else{
sb.append("'").append(listOfAnswers.get(i)).append("'").append(" is incorrect.");
wrongAnswers++;
feedbackAnswer(sb.toString(), false);
}
sb.append("\n");
}
}
}
private static void feedbackAnswer(String dialogMessageText, boolean isCorrect){
static void showFeedback(){
Alert alert = new Alert(Alert.AlertType.INFORMATION);
if (isCorrect) {
alert.setTitle("Correct!");
alert.setHeaderText("You got the right answer!");
}else{
alert.setTitle("Incorrect");
alert.setHeaderText("Sorry, that was incorrect");
}
alert.setContentText(dialogMessageText);
StringBuilder sb = new StringBuilder();
sb.append("You got ").append(correctAnswers).append(" out of ").append(correctAnswers+wrongAnswers).append("\n");
sb.append(Question.sb.toString());
alert.setTitle("You finished this part of the assessment!");
alert.setHeaderText("You finished this part of the assessment!");
Label label = new Label(sb.toString());
label.setWrapText(true);
alert.getDialogPane().setContent(label);
alert.showAndWait();
Question.sb = new StringBuilder();
AssessmentGenerator.totalCorrectAnswers += correctAnswers;
AssessmentGenerator.totalAnswers += (wrongAnswers + correctAnswers);
resetScore();
}
public static void resetScore(){
private static void resetScore(){
correctAnswers = 0;
wrongAnswers =0;
}