Загрузка...

Java Quiz Management System Project | GUI Application with Source Code. For Beginners...

📌 Java Quiz Management System..

✨Key Features:
MCQs, GUI Interface, Score Calculation

🔔 Don’t forget to like, share, and subscribe if you found it helpful!

📩 For any queries, feel free to contact me in the comments.

#JavaProject #JavaMicroproject #QuizApp #JavaSwing #FinalYearProject #JavaGUI

code is here.... 👉

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

public class JavaQuizGUI extends JFrame implements ActionListener {

String[][] questions = {
{"Which keyword is used to inherit a class in Java?", "this", "super", "extends", "implements", "3"},
{"What is the size of int in Java?", "2 bytes", "4 bytes", "8 bytes", "Depends on system", "2"},
{"Which method is the entry point for a Java program?", "main()", "start()", "run()", "init()", "1"},
{"Which of these is not a Java primitive type?", "int", "float", "String", "double", "3"},
{"Which package contains the Scanner class?", "java.io", "java.lang", "java.util", "java.net", "3"},
{"What does JVM stand for?", "Java Virtual Machine", "Java Visual Machine", "Just Virtual Machine", "Java Verified Machine", "1"},
{"Which keyword is used for exception handling?", "try", "catch", "finally", "All of the above", "4"},
{"Which collection class does not allow duplicates?", "List", "Set", "Map", "ArrayList", "2"},
{"Which loop is guaranteed to execute at least once?", "for", "while", "do-while", "none", "3"},
{"Which operator is used for comparison?", "=", "==", "!=", "&&", "2"},
{"Which class is the parent of all classes in Java?", "Object", "Class", "System", "Main", "1"},
{"How is memory managed in Java?", "By user", "Garbage collection", "Manually", "None", "2"},
{"Which interface stores key-value pairs?", "List", "Set", "Map", "Queue", "3"},
{"Which access modifier is default?", "private", "public", "protected", "default", "4"},
{"Which is not a Java feature?", "Platform independent", "Object-oriented", "Secure", "Pointer support", "4"}
};

int current = 0, score = 0;
ButtonGroup optionsGroup;
JRadioButton[] options = new JRadioButton[4];
JButton nextBtn;
JLabel questionLabel, qCounter;

public JavaQuizGUI() {
setTitle("Java Quiz - GUI Edition");
setSize(600, 400);
setLayout(null);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);

qCounter = new JLabel();
qCounter.setBounds(20, 10, 200, 30);
qCounter.setFont(new Font("Arial", Font.BOLD, 14));
add(qCounter);

questionLabel = new JLabel();
questionLabel.setBounds(20, 50, 550, 30);
questionLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
add(questionLabel);

optionsGroup = new ButtonGroup();
int y = 100;
for (int i = 0; i (less than) 4; i++) {
options[i] = new JRadioButton();
options[i].setBounds(30, y, 500, 30);
options[i].setFont(new Font("Tahoma", Font.PLAIN, 14));
optionsGroup.add(options[i]);
add(options[i]);
y += 40;
}

nextBtn = new JButton("Next");
nextBtn.setBounds(250, 280, 100, 30);
nextBtn.setFont(new Font("Tahoma", Font.BOLD, 14));
nextBtn.addActionListener(this);
add(nextBtn);

loadQuestion();
setVisible(true);
}

void loadQuestion() {
if (current (less than) questions.length) {
qCounter.setText("Question " + (current + 1) + " of " + questions.length);
questionLabel.setText("Q" + (current + 1) + ": " + questions[current][0]);
for (int i = 0; i (less than) 4; i++) {
options[i].setText(questions[current][i + 1]);
options[i].setSelected(false);
}
}
}

boolean checkAnswer() {
for (int i = 0; i (less than) 4; i++) {
if (options[i].isSelected() && (i + 1) == Integer.parseInt(questions[current][5])) {
return true;
}
}
return false;
}

public void actionPerformed(ActionEvent e) {
if (checkAnswer()) {
score++;
}
current++;
if (current == questions.length) {
showResult();
} else {
loadQuestion();
}
}

void showResult() {
JOptionPane.showMessageDialog(this,
"🎯 Quiz Completed!\n\nYour Score: " + score + " / " + questions.length +
"\nPercentage: " + String.format("%.2f", (score * 100.0 / questions.length)) + "%",
"Result",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}

public static void main(String[] args) {
new JavaQuizGUI();
}
}

I hope it will be helpful for you... ✨💫

Видео Java Quiz Management System Project | GUI Application with Source Code. For Beginners... канала Nikita Dhamal
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять