An application written in Java, used Java Swing and demo-ran in Netbeans, created to help optimize the process of learning vocabulary. Features of the application include: adding new English words, getting a suggested Vietnamese meaning of the entered English word via an Eng-Viet translation API, studying flashcards created in two language modes Eng-Viet or Viet-Eng, and testing your progress by taking quizzes, also available in both language modes.
Main Menu Window:
- Demonstration of inputing a new English word, fetching its suggested dictionary meaning and store it into saved items:
- Edit/delete or search for an item in the saved words list:
- Studying new words by using flashcards, easily switching between two language modes:
- Taking quizzes to test your vocabulary. Choose the number of words you want to be tested in a quiz, in Eng-Viet mode or Viet-Eng mode:
- Export your saved items into a .csv file that can easily be used in another application/website!
- Encapsulation
- Abstraction
- File Handling
- Arrays
- Inheritance
- Complex Selection
- Objects as data records
- Loops
- HashMap collections
- Use of flags
- Use of additional libraries (JSON)
Netbeans was used. JavaSwing GUI libraries are utilized to design how different GUI windows interact. Accessing translated Vietnamese meaning of an entered English word by retrieving the JSON response object from online API dictionary and converting the object to text with JSON libraries.
Figure 1: Parsing the required translation text from JSON response object
ArrayLists
Figure 2: An ArrayList storing English property as the key to identify Word objects
I used an ArrayList called keysArrayList to store the English representation of every word as String, which is the “key” to differentiate between Word objects. This is used to retreive such Word object from the dictionary (which is a HashMap collection). ArrayLists were chosen instead of other datatypes such as LinkedLists since ArrayList is a dynamically resizable array which allows efficiency of O(1) when stored data is accessed, consumes less memory than its counterparts. This means that regardless of the set size, the amount of time spent accessing data remains constant, which is particularly helpful for storing a large number of word inputs. Furthermore, using ArrayLists facilitates storing data in a dedicated manner, making future updates to the list straightforward.
HashMap collection (Objects as data records)
Figure 3: Dictionary HashMap creation
A HashMap is created to store the String and Word pairs, effectively pairing the English word string - the “key”, to the Word object itself. Therefore, we can retrieve a Word object knowing its English representation, avoiding assigning numerical indexes which can complicate the process of updating and accessing the Word objects.
Abstract TableModel
Figure 4: Constructing a table of saved words by getting Word objects’ properties in TableModel class
The table view of all saved items is constructed based on an Abstract TableModel class, which does not need to be instantiated for its object data to be accessed. Columns and rows of the table view are filled as this TableModel retrieved values from the aforementioned ArrayList that reads all the English-word keys (of the HashMap function) and their corresponding properties in Word objects. By modifying data of the Abstract TableModel, the table view is accordingly and instantaneously updated, with the use of a TableModel listener. The Delete Word and Edit Word features refer to this class and make changes to its data, while simulataneously updating the HashMap function that is the saved dictionary. Abstract TableModel is chosen over Default TableModel as it provides a convenient class that can extend to a model.
Edit a selected word
Figure 5: Method to edit a selected word
By accessing a Word object through its English key, user can make change to its other properties: the updated values are input through a JOptionPane. Creating a new Word object with these edited properties and retrieving the old Word object in the HashMap collection, I replace it with the new Word object, so that the dictionary is updated. Meanwhile, this word’s element in the TableModel is also modified, hence the table view is updated instantaneously.
Search word by RowSorter
Figure 6: Search word by RowSorter
By retrieving the user input of a word to search for from the engWordToSearch field, all saved items are filtered to match the input using RowSorter, a JavaSwing built-in method of filtering. The list of filtered items are updated everytime an additional letter is keyed; single-selection of word is enabled within this filtered list.
Figure 7: The class of Word utilizing encapsulation (OOP)
Encapsulation is used throughout the program to ensure that variables created are not inadvertently accessible by another class. Other objects cannot affect the internal state of encapsulated objects.
Figure 8: Properties of Question class
The Question class, inherited by Flashcard and Quiz class, is constructed to facilitate the use of Word objects in creating flashcards & quizzes. Question extends a Word object by including properties such as an array MCQ options, which are retrieved from English/Vietnamese meaning of other random words. This is achieved by methods of randomizing a set of numbers. There is also method to check if an option (String value) corresponds with the correct English/Vietnames meaning of the word in that Question object.
Random set of unique numbers
Figure 9: Method to geenrate a set of random unique numbers
A set of numbers within the range of the dictionary size is randomized by Java built-in Collections feature. These numbers then are used as indexes to retrieve Question objects from an ArrayList in a non-orderly manner, to shuffle the words used for flashcards and quizzes.
Figure 10: Flashcard class Constructor
An ArrayList of Question objects is used to store properties of all Word objects in the dictionary for the application to read from. A set of flashcards is generated when there is at least 4 words stored in the dictionary of the program. By using a while loop to iterate through the generateCard method to ensure all words are included in the Questions ArrayList.
For loop
Figure 11: Method to check for unique element in Question ArrayList
I implemented a for loop to check if elements in the Questions ArrayList are duplicated, so that the flashcards generated from this ArrayList presented to user are not repeated, until a cycle of all the words in the dictionary is shown (used in tandem with a Flashcard counter)
Figure 12: Flashcard counter flashCount in GUI class
Figure 13: Methods to calculate score for 2 different language modes
The Quiz class comprises a Question ArrayList of equal size to the number of questions chosen by user. There are 2 language modes in Quiz feature, English-Vietnamese and Vietnamese -English, so there are 2 sets of options, in 2 languages, which would be counterpart to the language of the question present, matching the mode choice. Display quiz options based on the ArrayList of 4 options (vietOptionsArrayList or engOptionsArrayList) that is a property of the Question object. There is a method to calculate score of Quiz by storing all selected options in an ArrayList and using method in Question class to check if they match the correct answer.
Figure 14: Switching to VietQuiz window based on mode selected
2 different language modes are separate into 2 different windows in the Quiz feature that switch on command of a ComboBox Listener. However, switching mode in Flashcard feature simply switches the order to which the 2 sides appear and reveal.
Figure 15: Different order of flashcard sides to appear and to be revealed in 2 modes
Figure 16: Writing data to local dictionary.dat file
To utilize the HashMap that stores pairs of English key and Word object, the program should be able to write to a local file to save the inputs without data loss across multiple relaunches. The FileKeep class creates an editable file in the local folder “dictionary.dat” and store values from the dictionary when application is closed. As application reopens, this file is read, and data is imported into the HashMap dictionary.
Represents how different windows and interfaces for each feature are linked together
Highlights the process of data flowing through the system when the program is running. This also shows the internal workings of the program as multiple commands write and read data.
Figure 1: Main Menu Window
Figure 2: Input new word Window
Figure 3: View saved words Window
Figure 4: Flashcard Window
Figure 5: Quiz Window – Mode English-Vietnamese
Figure 6: Quiz Window – Mode Vietnamese-English
Represents the processes running when the user interacts with the application and portrays how its different features work in tandem.
Generate a random Question and its multiple choices
Calculate score of a quiz
Randomize a set of flashcards
Fields | Data Types | Constraints | Example |
---|---|---|---|
English word | String | Not null | “apple” |
Suggested meaning | String | “táo” | |
Your own definition | String | “quả táo” | |
Words in context | String | “I have an apple” | |
Additional notes | String | "" |