DEV Community

Prasad Saya
Prasad Saya

Posted on

Notes About a Quiz App's Data

Few days back (14th Dec, 2022) I had posted an article on this website - A Short Story of an App. It was about a Quiz Web App with Java as subject as also the programming language used to develop the app. I had written that app in year 2013 and had revisited it couple of months back; the reason was to refine and data and the app. The above linked article has details about that app and the refinements.

One of the aspects of the app I had redesigned was the data (the quiz data) format as stored in a text file. In the refined app, the data format was JSON (refactored from a custom text format). This post is about creating the JSON data.

To maintain (add new quiz data items, modify and format it) the JSON data, I wrote an adhoc Java Swing desktop application (further referred as app). This post is to talk about the app.


The App

The app uses Java SE 8, Java Swing APIs for GUI (Graphical User Interface) and Gson Java library APIs for converting Java objects (the quiz data) to JSON and vice versa.

The app is written as six Java classes:

  • QuizData - Represents a quiz data item.
  • AppStarter - The main Java class starts the app.
  • QuizDataApp - The main GUI class, displays all quiz data items in a list and the user can perform operations on the data.
  • QuizDataDialog - The GUI window to edit a new or existing quiz data item.
  • FileUtils - This has methods to read and write to JSON file.
  • AppUtils - This defines constants and common methods.

The app has two GUI windows - one for listing all the quiz data items and the other for editing a new or existing quiz data item.

GUI Window shows all quiz data items

In the above picture, the listed items represent the quiz data items read from the JSON file. The user can create new items, delete an item from list and write the items to the JSON. Also, search question and options fields and perform update or delete operations on the resulting items.

To update an item in the list, select a list item and double-click it. This opens the quiz data window. The quiz data window (seen below) is used for editing new as well as existing data.

GUI Window to edit a quiz data item


Here is a sample quiz data item as JSON created by the app. This data is stored in a file json_data.txt.

{
    "id": 13,
    "question": "An abstract class has constructors.\n\nTrue or false:",
    "type": "S",
    "options": [
        "(a) True",
        "(b) False"
    ],
    "answers": [
        "a"
    ],
    "notes": [
        "True."
    ]
}
Enter fullscreen mode Exit fullscreen mode

You can compile and run the app and see how it works. The app's code is available at GitHub Repo : quiz-data-app.

Note that the app's GUI may look little different from the above screenshots as this sometimes depends upon the aspects like Java version or the computer's operating system.


Top comments (0)