Updated Assessment Controllers and FXML. Correct issue #31

Correct And Total answers are now displayed, the number and text are now displayed in the same text label to reduce issues with Screen Scaling
This commit is contained in:
law39 2020-05-01 11:08:16 +01:00
parent 5686d30859
commit 67d511f111
6 changed files with 87 additions and 102 deletions

View file

@ -40,14 +40,14 @@ public class MatchTheMeaningController extends SharedCodeController {
// Class variables. //
// //////////////// //
public static ArrayList<DictionaryEntry> answer =new ArrayList<>();
public static ArrayList<DictionaryEntry> answer = new ArrayList<>();
// /////////////////// //
// Instance variables. //
// /////////////////// //
private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0,1,2,3));
private boolean isEnglish = AssessmentGenerator.isEnglish;
private final ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3));
private final boolean isEnglish = AssessmentGenerator.isEnglish;
@FXML
private ComboBox<String> word1;
@ -86,10 +86,10 @@ public class MatchTheMeaningController extends SharedCodeController {
private Label RightWord4;
@FXML
private Label CorrectAnswer;
private Label correctAnswer;
@FXML
private Label WrongAnswer;
private Label totalAnswer;
// //////// //
// Methods. //
@ -103,10 +103,10 @@ public class MatchTheMeaningController extends SharedCodeController {
*/
public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList){
public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList) {
if(isEnglish){
if (isEnglish) {
LeftWord1.setText(questions.get(0).getEnglish());
LeftWord2.setText(questions.get(1).getEnglish());
LeftWord3.setText(questions.get(2).getEnglish());
@ -119,7 +119,7 @@ public class MatchTheMeaningController extends SharedCodeController {
RightWord3.setText(questions.get(orderList.get(2)).getWelsh());
RightWord4.setText(questions.get(orderList.get(3)).getWelsh());
}else {
} else {
LeftWord1.setText(questions.get(0).getWelsh());
LeftWord2.setText(questions.get(1).getWelsh());
LeftWord3.setText(questions.get(2).getWelsh());
@ -139,23 +139,23 @@ public class MatchTheMeaningController extends SharedCodeController {
* Check if answers from users are correct.
*/
public void checkAnswers(){
public void checkAnswers() {
ArrayList<DictionaryEntry> answers = new ArrayList<>();
ArrayList<String> listOfAnswers = new ArrayList<>();
answers.add(answer.get(Integer.parseInt(word1.getValue())-1));
answers.add(answer.get(Integer.parseInt(word2.getValue())-1));
answers.add(answer.get(Integer.parseInt(word3.getValue())-1));
answers.add(answer.get(Integer.parseInt(word4.getValue())-1));
answers.add(answer.get(Integer.parseInt(word1.getValue()) - 1));
answers.add(answer.get(Integer.parseInt(word2.getValue()) - 1));
answers.add(answer.get(Integer.parseInt(word3.getValue()) - 1));
answers.add(answer.get(Integer.parseInt(word4.getValue()) - 1));
if(isEnglish){
if (isEnglish) {
listOfAnswers.add(LeftWord1.getText());
listOfAnswers.add(LeftWord2.getText());
listOfAnswers.add(LeftWord3.getText());
listOfAnswers.add(LeftWord4.getText());
}else {
} else {
listOfAnswers.add(RightWord1.getText());
listOfAnswers.add(RightWord2.getText());
listOfAnswers.add(RightWord3.getText());
@ -163,13 +163,13 @@ public class MatchTheMeaningController extends SharedCodeController {
}
if(checkForDuplicates(answers)){
if (checkForDuplicates(answers)) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Please check answers");
alert.setContentText("Please ensure you have selected answers for each test word, with no duplicates.");
alert.showAndWait();
}else {
} else {
Question.checkAnswer(answers, listOfAnswers, isEnglish);
@ -178,19 +178,19 @@ public class MatchTheMeaningController extends SharedCodeController {
AssessmentGenerator.goToNextQuestion();
}
}
private boolean checkForDuplicates(ArrayList<DictionaryEntry> wordSet){
boolean result = false;
Set<DictionaryEntry> set = new HashSet<>(wordSet);
if(set.size() < wordSet.size()){
result = true;
}
return result;
private boolean checkForDuplicates(ArrayList<DictionaryEntry> wordSet) {
boolean result = false;
Set<DictionaryEntry> set = new HashSet<>(wordSet);
if (set.size() < wordSet.size()) {
result = true;
}
return result;
}
@FXML
@FXML
private void initialize() {
setup();
currentPageIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/pass-fail-50.png"));
@ -199,9 +199,11 @@ public class MatchTheMeaningController extends SharedCodeController {
studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png"));
studyText.setFill(Color.BLACK);
setWords(answer,orderList);
CorrectAnswer.setText(Integer.toString(AssessmentGenerator.getTotalCorrectAnswers()));
WrongAnswer.setText(Integer.toString(AssessmentGenerator.getTotalAnswers()));
setWords(answer, orderList);
correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers());
totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers());
}
}

View file

@ -16,7 +16,9 @@ import uk.ac.aber.cs221.group20.json.DictionaryEntry;
import uk.ac.aber.cs221.group20.selfassessment.AssessmentGenerator;
import uk.ac.aber.cs221.group20.selfassessment.Question;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* A class that generate questions and check answers for match the meaning test.
@ -45,16 +47,16 @@ public class SixMeaningsController extends SharedCodeController {
// Instance variables. //
// /////////////////// //
private ArrayList<DictionaryEntry> wordSet = new ArrayList<>();
private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5));
private final ArrayList<DictionaryEntry> wordSet = new ArrayList<>();
private final ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5));
private String wordCounterpart;
private boolean isEnglish = AssessmentGenerator.isEnglish;
private final boolean isEnglish = AssessmentGenerator.isEnglish;
@FXML
private Text correctAnswer;
private Label correctAnswer;
@FXML
private Text wrongAnswer;
private Label totalAnswer;
@FXML
private Label wordToTranslate;
@ -86,26 +88,31 @@ public class SixMeaningsController extends SharedCodeController {
wordCounterpart = possibleAnswer1.getText();
checkAnswers();
}
@FXML
void answer2(MouseEvent event) {
wordCounterpart = possibleAnswer2.getText();
checkAnswers();
}
@FXML
void answer3(MouseEvent event) {
wordCounterpart = possibleAnswer3.getText();
checkAnswers();
}
@FXML
void answer4(MouseEvent event) {
wordCounterpart = possibleAnswer4.getText();
checkAnswers();
}
@FXML
void answer5(MouseEvent event) {
wordCounterpart = possibleAnswer5.getText();
checkAnswers();
}
@FXML
void answer6(MouseEvent event) {
wordCounterpart = possibleAnswer6.getText();
@ -113,10 +120,9 @@ public class SixMeaningsController extends SharedCodeController {
}
public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList) {
public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList){
if(isEnglish){
if (isEnglish) {
wordSet.add(questions.get(0));
@ -132,7 +138,7 @@ public class SixMeaningsController extends SharedCodeController {
possibleAnswer4.setText(questions.get(orderList.get(3)).getWelsh());
possibleAnswer5.setText(questions.get(orderList.get(4)).getWelsh());
possibleAnswer6.setText(questions.get(orderList.get(5)).getWelsh());
}else {
} else {
wordSet.add(questions.get(0));
//WelshWord1 Is the question word and as a result is always right.
@ -153,15 +159,13 @@ public class SixMeaningsController extends SharedCodeController {
}
public void checkAnswers() {
ArrayList<String> answer = new ArrayList<>();
answer.add(wordCounterpart);
Question.checkAnswer(wordSet,answer,isEnglish);
Question.checkAnswer(wordSet, answer, isEnglish);
wordSet.clear();
@ -180,11 +184,11 @@ public class SixMeaningsController extends SharedCodeController {
studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png"));
studyText.setFill(Color.BLACK);
setWords(allQuestions,orderList);
correctAnswer.setText(Integer.toString(AssessmentGenerator.getTotalCorrectAnswers()));
setWords(allQuestions, orderList);
wrongAnswer.setText(Integer.toString(AssessmentGenerator.getTotalAnswers()));
correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers());
totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers());
}

View file

@ -1,28 +1,27 @@
package uk.ac.aber.cs221.group20.javafx;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import java.util.ArrayList;
import java.util.Random;
import uk.ac.aber.cs221.group20.json.DictionaryEntry;
import uk.ac.aber.cs221.group20.selfassessment.AssessmentGenerator;
import uk.ac.aber.cs221.group20.selfassessment.Question;
import java.util.ArrayList;
import java.util.Random;
/**
* Controller for the translationTest fxml file.
*
* @author Brad Corbett brc9
* @version 0.1
*
*/
public class TranslationController extends SharedCodeController{
public class TranslationController extends SharedCodeController {
// //////////////// //
// Class variables. //
@ -48,10 +47,10 @@ public class TranslationController extends SharedCodeController{
private Text wordToTranslate;
@FXML
private Text correctGuesses;
private Label correctAnswer;
@FXML
private Text incorrectGuesses;
private Label totalAnswer;
@FXML
private ImageView submitButton;
@ -68,7 +67,7 @@ public class TranslationController extends SharedCodeController{
* which is the first word the user will have to translate.
*/
@FXML
private void initialize(){
private void initialize() {
setup();
currentPageIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/pass-fail-50.png"));
currentPageText.setText("Study");
@ -76,17 +75,16 @@ public class TranslationController extends SharedCodeController{
studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png"));
studyText.setFill(Color.BLACK);
submitButton.setImage(new Image ("file:src/main/resources/assets/icons/black_icons/50px/right-50.png"));
submitButton.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png"));
correctGuesses.setText("Correct answers: " + AssessmentGenerator.getTotalCorrectAnswers());
incorrectGuesses.setText("Total answers: " + AssessmentGenerator.getTotalAnswers());
correctAnswer.setText("Correct answers : " + AssessmentGenerator.getTotalCorrectAnswers());
totalAnswer.setText("Total answers : " + AssessmentGenerator.getTotalAnswers());
if(AssessmentGenerator.isEnglish){
if (AssessmentGenerator.isEnglish) {
wordToTranslate.setText(answer.getEnglish());
}
else{
} else {
wordToTranslate.setText(answer.getWelsh());
}
}

View file

@ -128,30 +128,20 @@
<children>
<HBox alignment="TOP_RIGHT" prefHeight="0.0" prefWidth="583.0">
<children>
<Label text="Correct answers:">
<font>
<Font size="17.0" />
</font>
</Label>
<Label fx:id="CorrectAnswer" text="0">
<font>
<Font size="17.0" />
</font>
</Label>
<Label fx:id="correctAnswer">
<font>
<Font name="Consolas" size="17.0" />
</font>
</Label>
</children>
</HBox>
<HBox alignment="TOP_RIGHT" layoutX="10.0" layoutY="33.0" prefHeight="1.0" prefWidth="583.0">
<children>
<Label text="Total answers:">
<font>
<Font size="17.0" />
</font>
</Label>
<Label fx:id="WrongAnswer" text="0">
<font>
<Font size="17.0" />
</font>
</Label>
<Label fx:id="totalAnswer" layoutX="405.0" layoutY="50.0">
<font>
<Font name="Consolas" size="17.0" />
</font>
</Label>
</children>
</HBox>
<GridPane alignment="CENTER" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="150.0" prefWidth="400.0" VBox.vgrow="ALWAYS">

View file

@ -150,24 +150,14 @@
<font>
<Font size="14.0" />
</font></Text>
<Text fx:id="wrongAnswer" layoutX="554.0" layoutY="69.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0" wrappingWidth="22.46875">
<Label fx:id="totalAnswer" layoutX="405.0" layoutY="50.0">
<font>
<Font size="17.0" />
</font>
</Text>
<Label layoutX="405.0" layoutY="50.0" text="Incorrect answers:">
<font>
<Font size="17.0" />
<Font name="Consolas" size="17.0" />
</font>
</Label>
<Text fx:id="correctAnswer" layoutX="554.0" layoutY="43.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0">
<Label fx:id="correctAnswer" layoutX="405.0" layoutY="24.0">
<font>
<Font size="17.0" />
</font>
</Text>
<Label layoutX="411.0" layoutY="24.0" text="Correct answers:">
<font>
<Font size="17.0" />
<Font name="Consolas" size="17.0" />
</font>
</Label>
</children>

View file

@ -13,6 +13,7 @@
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.Label?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="uk.ac.aber.cs221.group20.javafx.TranslationController"
@ -140,16 +141,16 @@
<Font size="33.0" />
</font>
</Text>
<Text fx:id="correctGuesses" layoutX="407.0" layoutY="20.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Correct Guesses: 0" wrappingWidth="227.18359375">
<Label fx:id="totalAnswer" layoutX="405.0" layoutY="50.0">
<font>
<Font size="17.0" />
<Font name="Consolas" size="17.0" />
</font>
</Text>
<Text fx:id="incorrectGuesses" layoutX="407.0" layoutY="43.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Incorrect Guesses: 0">
</Label>
<Label fx:id="correctAnswer" layoutX="405.0" layoutY="24.0">
<font>
<Font size="17.0" />
<Font name="Consolas" size="17.0" />
</font>
</Text>
</Label>
<ImageView fx:id="submitButton" fitHeight="46.0" fitWidth="69.0" layoutX="398.0" layoutY="199.0" onMouseClicked="#translateWord" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>