Merge branch 'master' of https://gitlab.dcs.aber.ac.uk/ncw/gp20
This commit is contained in:
commit
125f59f09a
4 changed files with 130 additions and 128 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package uk.ac.aber.cs221.group20.javafx;
|
package uk.ac.aber.cs221.group20.javafx;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import uk.ac.aber.cs221.group20.json.DictionaryEntry;
|
import uk.ac.aber.cs221.group20.json.DictionaryEntry;
|
||||||
|
@ -96,6 +97,14 @@ public class Application extends javafx.application.Application {
|
||||||
practiceList.add(entry);
|
practiceList.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//When the user closes the application, it will automatically write the dictionary to a json file.
|
||||||
|
stage.setOnCloseRequest(e -> {
|
||||||
|
jsonProcessing.writeOutJson(jsonFileFinalLocation.getAbsolutePath(), Application.dictionary);
|
||||||
|
Platform.exit();
|
||||||
|
System.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
new ScreenSwitch(stage); // Initialise the ScreenSwitch class, passing the programs Stage as the parameter in order to display the first screen.
|
new ScreenSwitch(stage); // Initialise the ScreenSwitch class, passing the programs Stage as the parameter in order to display the first screen.
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,89 +18,145 @@ import uk.ac.aber.cs221.group20.javafx.Application;
|
||||||
* @author Luke Wybar [law39]
|
* @author Luke Wybar [law39]
|
||||||
* @author Marcin Jakob [maj83]
|
* @author Marcin Jakob [maj83]
|
||||||
* @author Oscar Pocock [osp1]
|
* @author Oscar Pocock [osp1]
|
||||||
* @author Tom Perry [top1]
|
* @author Tom Perry [top19]
|
||||||
* @author Waylen Watts [ncw]
|
* @author Waylen Watts [ncw]
|
||||||
* @version 0.1 Initial development
|
* @version 0.1 Initial development
|
||||||
* @see DictionaryController
|
* @see DictionaryController
|
||||||
*/
|
*/
|
||||||
public class DictionaryEntry {
|
public class DictionaryEntry {
|
||||||
private String english;
|
|
||||||
private String welsh;
|
|
||||||
public enum wordTypeEnum {
|
|
||||||
nm, nf, verb, other
|
|
||||||
}
|
|
||||||
private wordTypeEnum wordType;
|
|
||||||
// private String wordType;
|
|
||||||
private Boolean practiceWord;
|
|
||||||
|
|
||||||
|
// /////////////////// //
|
||||||
|
// Instance variables. //
|
||||||
|
// /////////////////// //
|
||||||
|
|
||||||
/**
|
private String english;
|
||||||
* Creates a new instance of a DictionaryEntry
|
private String welsh;
|
||||||
*/
|
public enum wordTypeEnum {
|
||||||
public DictionaryEntry() {
|
nm, nf, verb, other
|
||||||
practiceWord = false;
|
}
|
||||||
}
|
private wordTypeEnum wordType;
|
||||||
|
private Boolean practiceWord;
|
||||||
|
|
||||||
/**
|
// ///////////// //
|
||||||
* Creates new instance of a DictionaryEntry
|
// Constructors. //
|
||||||
*
|
// ///////////// //
|
||||||
* @param english english translation of the word
|
|
||||||
* @param welsh welsh translation of the word
|
|
||||||
* @param wordType type of word
|
|
||||||
* @see Application
|
|
||||||
* @see DictionaryController
|
|
||||||
*/
|
|
||||||
public DictionaryEntry(String english, String welsh, wordTypeEnum wordType) {
|
|
||||||
this.english = english;
|
|
||||||
this.welsh = welsh;
|
|
||||||
// this.wordType = wordType;
|
|
||||||
this.wordType = wordType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEnglish() {
|
/**
|
||||||
return english;
|
* Default constructor for DictionaryEntry.
|
||||||
}
|
*/
|
||||||
|
public DictionaryEntry() {
|
||||||
|
practiceWord = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void setEnglish(String english) {
|
/**
|
||||||
this.english = english.trim();
|
* Constructor that creates an instance of DictionaryEntry when given 'english', 'welsh' and 'wordType' parameters.
|
||||||
}
|
*
|
||||||
|
* @param english english translation of the word
|
||||||
|
* @param welsh welsh translation of the word
|
||||||
|
* @param wordType type of word
|
||||||
|
* @see Application
|
||||||
|
* @see DictionaryController
|
||||||
|
*/
|
||||||
|
public DictionaryEntry(String english, String welsh, wordTypeEnum wordType) {
|
||||||
|
this.english = english;
|
||||||
|
this.welsh = welsh;
|
||||||
|
this.wordType = wordType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getWelsh() {
|
// ////////////////////// //
|
||||||
return welsh;
|
// Read/Write properties. //
|
||||||
}
|
// ////////////////////// //
|
||||||
|
|
||||||
public void setWelsh(String welsh) {
|
/**
|
||||||
this.welsh = welsh.trim();
|
* Getter method for the 'english variable'.
|
||||||
}
|
*
|
||||||
|
* @return Current value of 'english'.
|
||||||
|
*/
|
||||||
|
public String getEnglish() {
|
||||||
|
return english;
|
||||||
|
}
|
||||||
|
|
||||||
public wordTypeEnum getWordType() {
|
/**
|
||||||
return wordType;
|
* Setter for the 'english' variable.
|
||||||
}
|
*
|
||||||
// public word getWordType() {
|
* @param english New String value for 'english'.
|
||||||
// return wordType;
|
*/
|
||||||
// }
|
public void setEnglish(String english) {
|
||||||
|
this.english = english.trim();
|
||||||
|
}
|
||||||
|
|
||||||
public void setWordType(wordTypeEnum wordType) {
|
/**
|
||||||
this.wordType = wordType;
|
* Getter for the 'welsh' variable.
|
||||||
}
|
*
|
||||||
|
* @return Current value of 'welsh'.
|
||||||
|
*/
|
||||||
|
public String getWelsh() {
|
||||||
|
return welsh;
|
||||||
|
}
|
||||||
|
|
||||||
// public void setWordType(String wordType) {
|
/**
|
||||||
// this.wordType = wordType;
|
* Setter for the 'welsh' variable.
|
||||||
// }
|
*
|
||||||
|
* @param welsh New String value for 'welsh'.
|
||||||
|
*/
|
||||||
|
public void setWelsh(String welsh) {
|
||||||
|
this.welsh = welsh.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the 'wordType' enum variable.
|
||||||
|
*
|
||||||
|
* @return Current value of the 'wordType'.
|
||||||
|
* @see wordTypeEnum
|
||||||
|
*/
|
||||||
|
public wordTypeEnum getWordType() {
|
||||||
|
return wordType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for the 'wordType' enum variable.
|
||||||
|
*
|
||||||
|
* @param wordType New wordTypeEnum value for the 'wordType'.
|
||||||
|
* @see wordTypeEnum
|
||||||
|
*/
|
||||||
|
public void setWordType(wordTypeEnum wordType) {
|
||||||
|
this.wordType = wordType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the 'practiceWord' variable.
|
||||||
|
*
|
||||||
|
* @return Current value of 'practiceWord'
|
||||||
|
*/
|
||||||
public Boolean isPracticeWord() {
|
public Boolean isPracticeWord() {
|
||||||
return practiceWord;
|
return practiceWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPracticeWord(Boolean practiceWord) {
|
/**
|
||||||
this.practiceWord = practiceWord;
|
* Setter for the 'practiceWord' variable.
|
||||||
}
|
*
|
||||||
|
* @param practiceWord New boolean value for 'practiceWord'.
|
||||||
|
*/
|
||||||
|
public void setPracticeWord(Boolean practiceWord) {
|
||||||
|
this.practiceWord = practiceWord;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
// //////// //
|
||||||
public boolean equals(Object entry) {
|
// Methods. //
|
||||||
DictionaryEntry otherEntry = (DictionaryEntry) entry;
|
// //////// //
|
||||||
|
|
||||||
return ((this.getWelsh().equalsIgnoreCase(otherEntry.getWelsh()) || this.getEnglish().equalsIgnoreCase(otherEntry.getWelsh())) &&
|
/**
|
||||||
this.getWordType().equals(otherEntry.getWordType()));
|
* Overidden equals method that checks to see if two Dictionary objects are equal to each other. This work by checking if the objects 'english' or 'welsh' variables are
|
||||||
}
|
* equal with the same 'wordType'.
|
||||||
|
*
|
||||||
|
* @param entry Object that the DictionaryEntry object is comparing itself to.
|
||||||
|
* @return Returns true (if equal) or false (not equal).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object entry) {
|
||||||
|
DictionaryEntry otherEntry = (DictionaryEntry) entry; // Cast the object to be a DictionaryEntry.
|
||||||
|
|
||||||
|
return ((this.getWelsh().equalsIgnoreCase(otherEntry.getWelsh()) || this.getEnglish().equalsIgnoreCase(otherEntry.getWelsh())) &&
|
||||||
|
this.getWordType().equals(otherEntry.getWordType())); // Check it they're equal by looking if they have equal 'welsh' or 'english' with the same 'wordType'.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package uk.ac.aber.cs221.group20.test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class FlashcardControllerTest {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package uk.ac.aber.cs221.group20.test;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import uk.ac.aber.cs221.group20.json.DictionaryEntry;
|
|
||||||
import uk.ac.aber.cs221.group20.selfassessment.AssessmentGenerator;
|
|
||||||
import uk.ac.aber.cs221.group20.javafx.TranslationController;
|
|
||||||
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.LinkedList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class TranslationControllerTest {
|
|
||||||
LinkedList<DictionaryEntry> practiceList = new LinkedList<>();
|
|
||||||
DictionaryEntry word1 = new DictionaryEntry("english1", "welsh1", "verb");
|
|
||||||
DictionaryEntry word2 = new DictionaryEntry("english2", "welsh2", "verb");
|
|
||||||
DictionaryEntry word3 = new DictionaryEntry("english3", "welsh3", "verb");
|
|
||||||
Random rand = new Random();
|
|
||||||
int chosenWord;
|
|
||||||
|
|
||||||
TranslationController controllerToTest = new TranslationController();
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void fillList(){
|
|
||||||
|
|
||||||
practiceList.add(word1);
|
|
||||||
practiceList.add(word2);
|
|
||||||
practiceList.add(word3);
|
|
||||||
chosenWord = rand.nextInt(practiceList.size());
|
|
||||||
TranslationController.answer = practiceList.get(0);
|
|
||||||
|
|
||||||
System.out.println(controllerToTest.wordToTranslate.getText());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRightWord(){
|
|
||||||
|
|
||||||
if(AssessmentGenerator.isEnglish){
|
|
||||||
assertEquals(TranslationController.answer.getEnglish(), controllerToTest.wordToTranslate.getText());
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
assertEquals("welsh1", controllerToTest.wordToTranslate.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Reference in a new issue