Skip to content

Latest commit

 

History

History
295 lines (181 loc) · 15.3 KB

README.md

File metadata and controls

295 lines (181 loc) · 15.3 KB

Vocabulary-App

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:

image

  1. Demonstration of inputing a new English word, fetching its suggested dictionary meaning and store it into saved items:

demo

  1. Edit/delete or search for an item in the saved words list:

demo saved words

  1. Studying new words by using flashcards, easily switching between two language modes:

Screen Recording 2022-05-12 at 19 24 35

  1. 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:

Screen Recording 2022-05-12 at 19 25 47

Screen Recording 2022-05-12 at 19 27 02

  1. Export your saved items into a .csv file that can easily be used in another application/website!

Documentation

DEVELOPMENT:

Complexities:

  • Encapsulation
  • Abstraction
  • File Handling
  • Arrays
  • Inheritance
  • Complex Selection
  • Objects as data records
  • Loops
  • HashMap collections
  • Use of flags
  • Use of additional libraries (JSON)

IDE & Java libraries used

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.

image

Figure 1: Parsing the required translation text from JSON response object
   

1. Word input storage Data structure & Presentation

    ArrayLists

  image
  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)

  image
  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

  image
  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

  image
  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

  image
  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.
   

2. Encapsulation

image

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.
   

3. Question class

image

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

  image
  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.
   

4. Flashcards (Inheritance)

image

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

  image
  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)

  image
  Figure 12: Flashcard counter flashCount in GUI class    

5. Quiz (Inheritance)

image

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.
   

6. Mode switching (Complex Selection)

image

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.    

image

Figure 15: Different order of flashcard sides to appear and to be revealed in 2 modes

7. File Handling

image

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.
   

DESIGN:

1. Hierarchical Chart

Represents how different windows and interfaces for each feature are linked together

image    

2. Data Flow Diagram

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.

image    

3. GUI elements

image

Figure 1: Main Menu Window
   

image

Figure 2: Input new word Window
   

image

Figure 3: View saved words Window
   

image

Figure 4: Flashcard Window
   

image

Figure 5: Quiz Window – Mode English-Vietnamese
   

image

Figure 6: Quiz Window – Mode Vietnamese-English
   

4. Flowchart

Represents the processes running when the user interacts with the application and portrays how its different features work in tandem.

image    

5. Key algorithms

Generate a random Question and its multiple choices

image

   

Calculate score of a quiz

image

   

Randomize a set of flashcards

image

   

6. UML Diagram

image

7. Data dictionary

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 ""