quiz application system in java

introduction

The Quiz application system is a Java GUI project for the operation of time bound quiz. It presents questions with multi-class options, user accepts reactions, and calculates the score immediately after submitting. Admins can add or modify questions, set the correct answer, and define the quiz period. 

The application provides feedback to users and maintains a performance records, making it suitable for schools, online testing, or learning platforms.

The Quiz application system is an interactive Java program designed to make, operate and evaluate quiz for students or participants. With a clean GUI, users can begin a time -bound quiz that contains multiple choice questions loaded with a database or file. 

The application randomly selects questions and evaluates answers in real time, showing the score at the end. Administrator users can add, modify or delete questions and correct choices using easy-to-use form. The project helps educational institutions, training centers, or human resource departments to assess and testify efficiently. 

Characteristics like question bank, score tracking and automatic grading make it a powerful tool for knowledge evaluation.

Key Features and Functionalities:

For Participants (Users):
  • Timed Quizzes: The application starts a countdown timer once the quiz begins. Users must complete the quiz within the given duration.

  • Multiple-Choice Questions (MCQs): Each question has 3 or 4 options, and the user selects the correct one using radio buttons.

  • Sequential Navigation: Questions are presented one at a time in a clean interface. Optional “Next” and “Previous” buttons may be used.

  • Auto-Submission: If the time limit is reached, the system automatically submits the quiz.

  • Instant Result Display: After submission, the system immediately calculates and displays the user’s score, including the number of correct and incorrect answers.

For Admins:
  • Add/Edit/Delete Questions: Admin can create a quiz by entering new questions, setting options, and marking the correct answer.

  • Quiz Configuration: Set quiz duration (in minutes), total number of questions, and passing score.

  • Question Database: Questions are stored in a file or database that the system pulls from during the quiz session.

  • Result Access (Optional): Admin can view previous scores if result logs are implemented.

steps to create quiz application system

  • Analyze quiz features — timed quiz, question bank, score display.

  • Design GUI for welcome screen, quiz question display, score summary.

  • Create Question class (question, options, correct answer).

  • Load questions from file or DB.

  • Implement timer using Java Timer class.

  • Track user answers and calculate score.

  • Add admin interface to add/edit/delete questions.

  • Test quiz flow end-to-end.

  • Improve with random question selection and categories.

  • Package and document.

code explanation

1. Constructor:

QuizApp()

  • Sets up the window size, title, and layout.

  • Adds the question label (lblQuestion) to the top.

  • Creates and adds 4 radio buttons (one for each answer option).

  • Adds a “Next” button at the bottom.

  • Loads the first question using

  • loadQuestion(currentQuestion).

2. loadQuestion(int index)

  • Displays the question and 4 answer options for the given question index.

  • Clears the previous selection.

  • Changes button text to “Submit” on the last question.

3. isAnswerSelected()

  • Checks whether the user has selected an answer (a radio button).

4. checkAnswer()

  • Finds which radio button is selected.

  • Compares it with the correct answer from the answers array.

  • If correct, increases the score.

5. ActionListener for

btnNext

  • When the “Next” or “Submit” button is clicked:

    • It checks if an answer is selected.

    • If yes:

      • Checks the answer and moves to the next question.

      • If it’s the last question, it shows the result.

6. showResult()

  • Shows a dialog with the final score after all questions are answered.

source code

				
					import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class QuizApp extends JFrame {

    private String[] questions = {
            "What is the capital of France?",
            "Which planet is known as the Red Planet?",
            "Who wrote 'Romeo and Juliet'?",
            "What is the boiling point of water?",
            "What is the largest mammal?"
    };

    private String[][] options = {
            {"Berlin", "Madrid", "Paris", "London"},
            {"Earth", "Mars", "Jupiter", "Venus"},
            {"William Shakespeare", "Charles Dickens", "Mark Twain", "Leo Tolstoy"},
            {"100°C", "90°C", "120°C", "80°C"},
            {"Elephant", "Blue Whale", "Giraffe", "Hippopotamus"}
    };

    private int[] answers = {2, 1, 0, 0, 1};  // Correct options indexes

    private int currentQuestion = 0;
    private int score = 0;

    private JLabel lblQuestion;
    private JRadioButton[] radioOptions;
    private ButtonGroup optionsGroup;
    private JButton btnNext;

    public QuizApp() {
        setTitle("Simple Quiz Application");
        setSize(600, 350);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setLayout(new BorderLayout(10, 10));

        // Question label
        lblQuestion = new JLabel("Question");
        lblQuestion.setFont(new Font("SansSerif", Font.BOLD, 18));
        lblQuestion.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
        add(lblQuestion, BorderLayout.NORTH);

        // Options panel with radio buttons
        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new GridLayout(4, 1, 10, 10));
        optionsPanel.setBorder(BorderFactory.createEmptyBorder(10, 40, 10, 40));

        radioOptions = new JRadioButton[4];
        optionsGroup = new ButtonGroup();

        for (int i = 0; i  {
            if (isAnswerSelected()) {
                checkAnswer();
                currentQuestion++;
                if (currentQuestion < questions.length) {
                    loadQuestion(currentQuestion);
                } else {
                    showResult();
                }
            } else {
                JOptionPane.showMessageDialog(this, "Please select an answer.");
            }
        });

        loadQuestion(currentQuestion);
    }

    private void loadQuestion(int index) {
        lblQuestion.setText("Q" + (index + 1) + ": " + questions[index]);
        optionsGroup.clearSelection();
        for (int i = 0; i < 4; i++) {
            radioOptions[i].setText(options[index][i]);
        }
        if (index == questions.length - 1) {
            btnNext.setText("Submit");
        } else {
            btnNext.setText("Next");
        }
    }

    private boolean isAnswerSelected() {
        for (JRadioButton radio : radioOptions) {
            if (radio.isSelected()) {
                return true;
            }
        }
        return false;
    }

    private void checkAnswer() {
        for (int i = 0; i  {
            new QuizApp().setVisible(true);
        });
    }
}


				
			

output

More java Pojects
Get Huge Discounts