Notes About a Quiz App's Data
Tags: java, programming
Published: 2022-12-21 10:16:44

Few days back (14th Dec, 2022) I had posted an article on this website - [A Short Story of an App](https://dev.to/prsaya/a-short-story-of-an-app-3hgb). 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdru31a3tttxh0pa12bk.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w313eraqj9ckogxgcs28.png)

---

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

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

---

You can **compile and run** the app and see how it works. The app's code is available at GitHub Repo : [quiz-data-app](https://github.com/prsaya/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.

---