0% found this document useful (0 votes)
28 views40 pages

CPP Micro-Project

The document outlines the development of a mobile quiz application aimed at enhancing educational technology by providing an interactive platform for knowledge assessment in classrooms. It includes acknowledgments, project planning, requirements, design, development, and testing processes, emphasizing the importance of quality assurance and effective project management. The application is intended to facilitate learning and recruitment processes, making it a valuable tool for both students and software companies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views40 pages

CPP Micro-Project

The document outlines the development of a mobile quiz application aimed at enhancing educational technology by providing an interactive platform for knowledge assessment in classrooms. It includes acknowledgments, project planning, requirements, design, development, and testing processes, emphasizing the importance of quality assurance and effective project management. The application is intended to facilitate learning and recruitment processes, making it a valuable tool for both students and software companies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Rajiv Gandhi polytechnic Quiz game

ACKNOWLEDGEMENT

Dreams never turn into reality unless a lot of efforts and hard work is put into it and
no effort ever bears fruit in the absence of the support and guidance. It takes a lot
of efforts to make your way to the goal and having someone to guide you and help
you is always a blessing. We would like to take this opportunity to thank a few
who were closely involved in the completion of this endeavor.

We are highly grateful to our Principal, Prof.MR.P.D.JADHAV, for making available


through the department the help needed in the form of facilities & guidance.

We are happy to take this opportunity to thank the people who helped us in the
making of our Project. We acknowledge the influence and inspiration of
Prof.Mrs.SHAIKH.P.K, HOD of Computer Engineering Department for their valuable
support and providing necessary Guidance concerning projects implementation.

We are also grateful to our guides (Prof.Miss.K.D.Patil) for provision of expertise and
technical support in the implementation. Without their superior knowledge and
experience, the project would not be possible. We are also thankful to our entire
Computer engineering staff for their support in completing this project.

We are thankful to Prof.Mrs.SHAIKH.P.K (Project Coordinator) for providing us the


required infrastructure to carry our project work.

Last but not least most importantly, we would like to pay our utmost regards to our
beloved parents and faculty members for their blessing without which success is a
mirage.

Computer Engineering 2024-25 Page | 1


Rajiv Gandhi polytechnic Quiz game

INDEX

Sr. No Topic Page


No.
1 1 Abstract
2 2.1 Introduction
2.2 Need
2.3 Project Background
2.4 Proposed System

3 3.1 Project Plannig


3.2 Module
3.3 Quality Assurance Plan
3.4 Project Scheduling
4 4.1 Project Requirement
4.2 Software Requirement
4.3 Hardware Requirement

5 5.1
Project Design
5.2 Input Design
5.3 Output Design
6 6.1 System Development
6.2 System Analysis
7 7.1 System Testing
7.2 Test Plan
7.3 Test Design
8 8.1 Future Enhancement
9 9.1 Bug Report
10 10.1 Code
10.2 Snapshots
11 11.1 Conclusion
12 12.1 Bibliography

Computer Engineering 2024-25 Page | 2


Rajiv Gandhi polytechnic Quiz game

1.ABSTRACT

Educational Technology is constantly evolving and growing, and this progression


will
continually offer new and interesting advances in learning environment.
Traditional E-Learning systems developed for laptop and desktop computers
were based on stand-alone software application and web based application
architecture. These applications have many limitations to use efficiently or we
cannot use them easily since these applications need a computing device and
network connectivity. With the advancement in mobile technology and
availability of smart mobile devices and network we can design a system which
can be used to check the knowledge level of students in the class room.

Since mobile network is available at large geographical area so this can be


knowledge testing of any person specially candidates of software companies who
need a specific skill for the job. Thus the main objective of the research work is
to develop an interactive mobile application based on android framework to
conduct quiz sessions in the classroom for the various technical topics. used for
the

This paper deals with the prototype development of an Mobile quiz system,
comprehensive evaluation system for the remote students or in a classroom. On
further enhancement this app can be used for the recruitment process of software
companies which will be able to save time and efforts to illuminate unwanted
candidates to appear for personal interview by travelling a long distance
Keywords:- Android, Mobile Learning, Mobile Evaluation, E-Learning

2.Introduction
2.1 Need

Computer Engineering 2024-25 Page | 3


Rajiv Gandhi polytechnic Quiz game

It offers online instruction that can be delivered anytime and anywhere through a wide
range of electronic learning solutions such as Web-based course ware. online
discussion groups, live virtual classes, video and audio streaming, Web chat, online
simulations, and virtual mentoring E Learning enables organizations to transcend
distance and other organizational gaps by providing a cohesive virtual learning
environment. Companies must educate and train vendors, employees, partners, and
clients to stay competitive and E-Learning can provide such just-in-time training in a
cost-effective way. Developing and deploying effective E-Learning programs may
require products and services supplied by a variety of vendors, leavingone to connect
the dots. One way to start is to define the goals of the desired learning solution.

2.2 Existing System

The current situation is very limited to few resources, students are unable to get
knowledge more than that the lecture provides to them. This in the end limits student's
performances, because everything a student gets is collected from lectures in class.

2.3 Project Background

This project is aimed at developing an online search Portal for the Placement Details
for job seekers The system is an online application that can be accessed throughout the
organization and outside as well with proper login provided. This system can be used
as an Online Job Portal for job seekers Job Seekers logging should be able to upload
their information in the form of a CV Visitors/Company representatives logging in
may also access/search any information put up by Job aspirants

2.4 Proposed system

Computer Engineering 2024-25 Page | 4


Rajiv Gandhi polytechnic Quiz game

The system will hopefully serve as a centralized database of


syllabus for the courses offered at the university allowing students and
faculties (current, past and prospective), to view them. The system will
end up bringing an effective communication among students, lectures, and
the administration, by accessing information and other resources anytime,
anywhere.

Computer Engineering 2024-25 Page | 5


Rajiv Gandhi Polytechnic, Udgir Quiz game

3.Project Planning

A software project development is a highly labour-intensive activity. Large


software may involve hundreds of people and span of time. A project in it is
dimension can easily turn into chaos if proper management is not done. Proper
management controls and checkpoints are required for effective project
monitoring. Controlling the development, ensuring quality, satisfying the
constraints of the selective process model are require careful management of the
project.

3.l The major issue the project plan addresses are:


• Cost estimation

• Schedule and milestone

• Personal plan

• Software quality assurance

• Configuration management plan

• Project monitoring plans

• Risk management

3.2 Quality Assurance Plan:

To ensure that the final product is of high quality, some quality control activities
must be performed throughout the development. As we saw earlier, if this is not
done, correcting errors in the final stages can be vary expansive, especially if they
originated in the early phases. The purpose of the software quality assurance plans
(SQAP) is to specify all the work products that need to be Note that SQAP takes a
board view quality.

Computer Engineering 2024-25 6|Page


Rajiv Gandhi Polytechnic, Udgir Quiz game

It is interested in the quality of not only the final product, but also of the
intermediate products, even though in a project we are ultimately interested in the
quality of the delivered product. This is since in a project it is very unlikely that
the intermediate work products are of poor quality, but the final product is of high
quality. So, to ensure that the delivered software is of good quality it is essential to
make sure that the requirements and design are also of good quality.

3.3Project Scheduling

It is important, right at the start of the design process, for the designer or design
team, to set clear objective. The primary objectives will always be to design a
system that delivers the functions required by the client to support the business
objective of their organization. For example, the system may be required to speed
up the production of accurate invoices, or to provide up to date, detailed
management information to improve the managing director's control over the
business; or to help senior managers to make strategic decisions. In the other
words, to be a quality product — the system must conform to the customer's
requirements and be delivered in a way, which meets their expectations in terms of
service. There are many ways in which these requirements might be met by a
physical design solution, but there are a number of other objectives that must be
considered if a god design is to be produced.

Computer Engineering 2024-25 7|Page


Rajiv Gandhi Polytechnic, Udgir Quiz game

3.4Project Scheduling

Weeks Week 1 Week 2 Week 3 Week 4



Months

Month 1 Making team Finding project to Discuss with Fix the name of the
member to make software. team members software.
make software. for selecting the
project name.

Month 2 Search the Gather Study the Documentation is


information of requirements of requirement by done.
that project. that project. the team member.
Month 3 Communication Planning of the Requirement Making a expected
with team project. analysis. result of that
members about project.
the requirement.

Month 4 Starting of Select the Study of that Finding which


designing part. language which is language. database is suitable
used for software for that software.
and good to view.

Month 5 Making design Completing the Making test Developer studies


as simple for design part. cases. the language.
coding and
attractive to see.

Month 6 Developer takes Write the code of It implements as Coding Making.


design and start that project. per the customer
of coding. want.
Month 7 If new Completing the Transfer to the It finds the defect
requirement is coding part. testing team and in that code.
come then start the testing.
change it and
make coding.

Month 8 If error is occur By using the bug Checking the Deploy to the
then fix it by the track system the actual result with customer.
tester or bugs are fixed. the expected
developer. result.

Computer Engineering 2024-25 8|Page


Rajiv Gandhi Polytechnic, Udgir Quiz game

Computer Engineering 2024-25 9|Page


Rajiv Gandhi Polytechnic, Udgir Quiz game

4 .Project Requirement
4.1 Software Requirement
 Operating System : Windows 7 or Onwards
 Language : JAVA
 Backend : JAVA

4.2 Hardware Requirement


 Processor : i3
 Hard Disk : 16 GB or more
 Memory : 4GB or more

Computer Engineering 2024-25 Page | 10


Rajiv Gandhi Polytechnic, Udgir Quiz game

5. Project Design
DFD :1

Computer Engineering 2024-25 Page | 11


Rajiv Gandhi Polytechnic, Udgir Quiz game

Computer Engineering 2024-25 Page | 12


Rajiv Gandhi Polytechnic, Udgir Quiz game

6.System Development
System Development

System development is the next process after the software specification document is created with
all the required UML diagrams. This activity is the process of writing and maintaining the source
code. The application was developed using the MVC design pattern. The MVC improves
development by breaking the application into distinct components: the model, the view and the
controller. The model represents an object carrying data which has logic to update the controller
if the data changes. The view is the collection of classes for the visualization of the data that
contains the model. The controller represents the classes connecting the model and the view and
controls the user with the view into actions that the model will perform. Using MVC, the
business logic can be reused in some other projects as well, and thus developers' time is
saved when rewriting the same code. The code will also be much easier to read and understand.

More functionalities and features were added to the intermediate version of the Training
Management System. A search engine is one of the features of the application that was added to
make it fast and easy for trainees to register themselves into the training. If a trainee has already
registered into some training before, or if he/she is in the database of the application, the trainee
will

not have to fill in all the fields of the registration form. Instead, the trainee just

types his/her name and the suggestions are shown in the drop-down view. When the trainee
clicks to the drop-down view of his/her information, all the fields are automatically filled with all
his/her data that are stored in the database and he/she can register easily into the training

Another functionality that was added to the intermediate version of the app was the user's input
validation while filling in the form. The user fills in the form

and presses the submit button to register into the training. Before registering the user to the
training, the system will check each field's input. For example, in the email field the user input
should be the formatted email input like [email protected]. In the last name
and first name fields the system shows an error if the user has input some numbers. Only the
badge number and department fields can be left empty. Rather than these two fields, if other
fields are left empty, the system will not register the user to training. Instead, it will give the
error message, so that the user can easily figure out his/her mistake while registering into
training.

The components that make up the system were tested during the development

process. Each component was tested independently without other system components. The
components that were tested were functions, objects, methods or coherent grouping of these
entities

Computer Engineering 2024-25 Page | 13


Rajiv Gandhi Polytechnic, Udgir Quiz game

7.SYSTEM TESTING
System testing is the expensive and time-consuming process. There are two

Strategies for testing software that we use for testing our system: Code testing and Specification
Testing. In Code testing, we developed those cases to execute every instructions and path in
the program. In specification testing, we examined the program specification and then wrote
test data to determine how the program operates under specified condition. The different levels
of testing are used in the testing process. The basic levels are unit testing, integration testing,
system testing, and acceptance testing. These different levels of testing detect different types of
faults.

7.1Defect Testing:— Testing involves executing the program (or part of it) using sample data
and inferring from the output whether the software performs correctly or not. This can be done
either during module development (unit testing) or when several modules are combined (system
testing).

7.2 Defect Testing:- Defect testing is testing for situation where the

program does not meet its fictional specification. Performance testing tests a

system's performance or reliability under realistic loads. This may go some way to ensuring that
the program meets its non-functional requirements.

7.3Debugging: — Debugging is a cycle of detection, location, repair and test. Debugging is a


hypothesis testing process. When a bug is detected, the tester must form a hypothesis about the
cause and location of the bug. Further examination of the execution of the program (possible
including many returns of it) will usually take place to confirm the hypothesis. If the hypothesis
is demonstrated to be incorrect, a new hypothesis must be formed. Debugging tools that show
the state of the program are useful for this, but inserting print statements is often the only
approach. Experienced debuggers use their knowledge of common and/or obscure bugs to
facilitate the hypothesis testing process. After fixing a bug, the system must be reset to ensure
that the fix has worked and that no other bugs have been introduced. This is called regression

testing. In principle, all tests should be performed again but this is often too expensive to do.

7.4Black-box (Functional) Testing:


Testing against specification of system or component. Study it by examining its inputs and
related outputs. Key is to devise inputs that have a higher likelihood of causing outputs that
Computer Engineering 2024-25 Page | 14
Rajiv Gandhi Polytechnic, Udgir Quiz game

reveal the presence of defects. Use experience and knowledge of domain to identify such test
cases. Failing this a systematic approach may be necessary. Equivalence partitioning is where
the input to a program falls into a number of classes. E.g. positive numbers vs. negative
numbers. Programs normally behave the same way for each member of a class. Partitions exist
for both input and output. Partitions may be discrete or overlap. Invalid data (i.e. outside the
normal partitions) is one or more partitions that should be tested. Test cases are chosen to
exercise each portion. Also test boundary cases (atypical, extreme, zero) since these frequently
show up defects. For completeness, test all combinations of partitions. Black box testing is rarely
exhaustive (because one doesn't test every value in an equivalence partition) and sometimes fails
to reveal corruption defects caused by "weird" combination of inputs. Black box testing should
not be used to try and reveal corruption defects caused, for example, by assigning a pointer to
point to an object of the wrong type. Static inspection (or using a better programming language!)
is preferable for this.

7.5White-box (structural) Testing:


Testing based on knowledge of structure of component (e.g. by looking at
source code). Advantage is that structure of code can be used to find out how many test cases
need to be performed. Knowledge of the algorithm (examination of the code) can be used to
identify the equivalence partitions. Path testing is where the tester aims to exercise every
independent execution path through the component. All conditional statements tested for both
true and false cases. If a unit has no control statements, there will be up to 2n possible paths
through it. This demonstrates that it is much easier to test small program units than large ones.
Flow graphs are a pictorial representation of the paths of control through a program (ignoring
assignments, procedure calls and I/O statements). Use flow graph to design test cases that
execute each path. Static tools may be used to make this easier in programs that have a complex
branching structure. Tools support. Dynamic program analysers instrument a program with
additional code. Typically, this will count how many times each statement is executed. At end,
print out report showing which statements have and have not been executed.

Computer Engineering 2024-25 Page | 15


Rajiv Gandhi Polytechnic, Udgir Quiz game

8.FutureEnhancement

1) To modify the Online Examination System project to .Net platform to take the advantage of
geographical remote area. By shifting the project to the Dot Net platform, the project can be
made into a Mobile Accessible Application by which the restrictions of the software & hardware
requirements can he scaled down, which is not possible using ASP.

2) we can even apply the unique identity of the user by keeping certain
formalities which must be answered by the user while entering the test (like the user need to
answer again the questions which he did while registering himself for the test) the questions
selected will be in random order from his personal data only (like the mole present on the user,
etc ...) so that we it may confirm that the user itself is writing the test .

3) we can even use the thumb mark of the users to confirm their identities.
4) We can even add the photos of the users in this to confirm the user Identity. Thus by applying
these steps we can make sure that the user itself is writing the exam not the others.

Computer Engineering 2024-25 Page | 16


Rajiv Gandhi Polytechnic, Udgir Quiz game

Bug ID: 01 Release: 07/04/2025

Version: 1.0 Tester: Mangesh Date: 15/04/2025

Assigned to: Mangesh Severity: 01 Priority: 01

Title: Response Text Field Auto-fills Unexpectedly

Description: When a user completes one question and moves to the next, the response
field auto-fills with the question number instead of being cleared.

Resolution: Fixed/Duplication/can’t Resolution: Fixed Bug

Fix/won’t fix deferred

Retested by: Aditya Version Tested: 01

Date tested: 14/04/2025 Retest comment: Bug Fixed

9. BUG REPORT

Computer Engineering 2024-25 Page | 17


Rajiv Gandhi Polytechnic, Udgir Quiz game

10.CODE
10.1 Advance Java Code:-

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;

public class AdminPanel {


private JFrame frame;
private JTextField questionField, option1Field, option2Field, option3Field, option4Field;
private JComboBox<String> correctOptionBox;
private Connection connection;

public AdminPanel() {
connectToDatabase();
createAdminGUI();
}

private void connectToDatabase() {


try {
String url = "jdbc:mysql://localhost:3306/quizgame";
String user = "root";
String pass = "abhi@123";
connection = DriverManager.getConnection(url, user, pass);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Database Connection Failed!", "Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}

private void createAdminGUI() {


frame = new JFrame("Admin Panel - Add Questions");
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JPanel panel = new JPanel();


panel.setLayout(new GridLayout(7, 2, 10, 10));

panel.add(new JLabel("Question:"));
questionField = new JTextField();
panel.add(questionField);
Computer Engineering 2024-25 Page | 18
Rajiv Gandhi Polytechnic, Udgir Quiz game

panel.add(new JLabel("Option 1:"));


option1Field = new JTextField();

panel.add(option1Field);

panel.add(new JLabel("Option 2:"));


option2Field = new JTextField();
panel.add(option2Field);

panel.add(new JLabel("Option 3:"));


option3Field = new JTextField();
panel.add(option3Field);

panel.add(new JLabel("Option 4:"));


option4Field = new JTextField();
panel.add(option4Field);

panel.add(new JLabel("Correct Option (1-4):"));


correctOptionBox = new JComboBox<>(new String[]{"1", "2", "3", "4"});
panel.add(correctOptionBox);

JButton addButton = new JButton("Add Question");


addButton.addActionListener(e -> addQuestion());
panel.add(addButton);

JButton viewScoresButton = new JButton("View Scores");


viewScoresButton.addActionListener(e -> showScores());
panel.add(viewScoresButton);

panel.add(new JLabel("Update Question ID:"));


JTextField updateField = new JTextField();
panel.add(updateField);

JButton loadButton = new JButton("Load for Edit");


loadButton.addActionListener(e -> {
String idText = updateField.getText();
if (!idText.isEmpty()) {
try {
int qid = Integer.parseInt(idText);
loadQuestionForEdit(qid);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid Question ID", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
});
panel.add(loadButton);

JButton updateButton = new JButton("Update Question");


updateButton.addActionListener(e -> {
Computer Engineering 2024-25 Page | 19
Rajiv Gandhi Polytechnic, Udgir Quiz game

String idText = updateField.getText();


if (!idText.isEmpty()) {
try {
int qid = Integer.parseInt(idText);
updateQuestion(qid);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid Question ID", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
});
panel.add(updateButton);

panel.add(new JLabel("Delete Question ID:"));


JTextField deleteField = new JTextField();
panel.add(deleteField);

JButton deleteButton = new JButton("Delete Question");


deleteButton.addActionListener(e -> {
String idText = deleteField.getText();
if (!idText.isEmpty()) {
try {
int qid = Integer.parseInt(idText);
deleteQuestion(qid);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid Question ID", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
});
panel.add(deleteButton);

JButton logoutButton = new JButton("Logout");


logoutButton.addActionListener(e -> {
frame.dispose();
new QuizSystem();
});
panel.add(logoutButton);

frame.add(panel);
frame.setVisible(true);
}

private void addQuestion() {


String question = questionField.getText();
String option1 = option1Field.getText();
String option2 = option2Field.getText();
String option3 = option3Field.getText();
Computer Engineering 2024-25 Page | 20
Rajiv Gandhi Polytechnic, Udgir Quiz game

String option4 = option4Field.getText();


int correctOption = Integer.parseInt((String) correctOptionBox.getSelectedItem());

if (question.isEmpty() || option1.isEmpty() || option2.isEmpty() || option3.isEmpty() ||


option4.isEmpty()) {
JOptionPane.showMessageDialog(frame, "All fields are required!", "Warning",
JOptionPane.WARNING_MESSAGE);
return;

try {
String query = "INSERT INTO questions (question, option1, option2, option3, option4,
correct_option) VALUES (?, ?, ?, ?, ?, ?)";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, question);
stmt.setString(2, option1);
stmt.setString(3, option2);
stmt.setString(4, option3);
stmt.setString(5, option4);
stmt.setInt(6, correctOption);
stmt.executeUpdate();

JOptionPane.showMessageDialog(frame, "Question Added Successfully!");


clearFields();
} catch (SQLException e) {
JOptionPane.showMessageDialog(frame, "Error adding question!", "Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}

private void deleteQuestion(int questionId) {


try {
String query = "DELETE FROM questions WHERE id = ?";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setInt(1, questionId);
int rows = stmt.executeUpdate();
if (rows > 0) {
JOptionPane.showMessageDialog(frame, "Question Deleted!");
} else {
JOptionPane.showMessageDialog(frame, "Question ID not found.");
}
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(frame, "Error deleting question!");
}
}

private void loadQuestionForEdit(int questionId) {


try {
Computer Engineering 2024-25 Page | 21
Rajiv Gandhi Polytechnic, Udgir Quiz game

String query = "SELECT * FROM questions WHERE id = ?";


PreparedStatement stmt = connection.prepareStatement(query);
stmt.setInt(1, questionId);
ResultSet rs = stmt.executeQuery();

if (rs.next()) {
questionField.setText(rs.getString("question"));
option1Field.setText(rs.getString("option1"));
option2Field.setText(rs.getString("option2"));
option3Field.setText(rs.getString("option3"));
option4Field.setText(rs.getString("option4"));
correctOptionBox.setSelectedIndex(rs.getInt("correct_option") - 1);
} else {
JOptionPane.showMessageDialog(frame, "Question not found!");
}
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(frame, "Error loading question!");
}
}

private void updateQuestion(int questionId) {


try {
String query = "UPDATE questions SET question=?, option1=?, option2=?, option3=?, option4=?,
correct_option=? WHERE id=?";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, questionField.getText());
stmt.setString(2, option1Field.getText());
stmt.setString(3, option2Field.getText());
stmt.setString(4, option3Field.getText());
stmt.setString(5, option4Field.getText());
stmt.setInt(6, Integer.parseInt((String) correctOptionBox.getSelectedItem()));
stmt.setInt(7, questionId);

int rows = stmt.executeUpdate();


if (rows > 0) {
JOptionPane.showMessageDialog(frame, "Question updated!");
clearFields();
} else {
JOptionPane.showMessageDialog(frame, "Question ID not found!");
}
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(frame, "Error updating question!");
}
}

private void showScores() {


try {
Computer Engineering 2024-25 Page | 22
Rajiv Gandhi Polytechnic, Udgir Quiz game

String query = "SELECT username, score, total, date_taken FROM scores ORDER BY date_taken
DESC";
PreparedStatement stmt = connection.prepareStatement(query);
ResultSet rs = stmt.executeQuery();

JTable table = new JTable(buildTableModel(rs));


JOptionPane.showMessageDialog(null, new JScrollPane(table), "Score Board",
JOptionPane.INFORMATION_MESSAGE);

} catch (SQLException e) {
e.printStackTrace();
}
}

// Utility method to convert ResultSet to TableModel


private static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
Vector<String> columnNames = new Vector<>();
for (int i = 1; i <= columnCount; i++) {
columnNames.add(metaData.getColumnName(i));
}

Vector<Vector<Object>> data = new Vector<>();


while (rs.next()) {
Vector<Object> row = new Vector<>();
for (int i = 1; i <= columnCount; i++) {
row.add(rs.getObject(i));
}
data.add(row);
}

return new DefaultTableModel(data, columnNames);


}

private void clearFields() {


questionField.setText("");
option1Field.setText("");
option2Field.setText("");
option3Field.setText("");
option4Field.setText("");
correctOptionBox.setSelectedIndex(0);
}

public static void main(String[] args) {


new AdminPanel();
}
}

Computer Engineering 2024-25 Page | 23


Rajiv Gandhi Polytechnic, Udgir Quiz game

2. Question Panal
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class QuestionPanel {


private JFrame frame;
private JLabel questionLabel;
private JRadioButton option1, option2, option3, option4;
private ButtonGroup optionsGroup;
private JButton nextButton;
private Connection connection;
private ResultSet questions;
private int currentQuestionIndex = 1;
private String username;
private int totalQuestions = 0;
private int correctAnswers = 0;
private String correctAnswer;

public QuestionPanel(String username, Connection conn) {


this.username = username;
this.connection = conn;
createGUI(username);
loadQuestions();
}

private void createGUI(String username) {


frame = new JFrame("Quiz - Welcome " + username);
frame.setSize(600, 400);
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

questionLabel = new JLabel("Question here");


questionLabel.setFont(new Font("Arial", Font.BOLD, 16));
questionLabel.setHorizontalAlignment(JLabel.CENTER);

option1 = new JRadioButton();


option2 = new JRadioButton();
option3 = new JRadioButton();
option4 = new JRadioButton();
Computer Engineering 2024-25 Page | 24
Rajiv Gandhi Polytechnic, Udgir Quiz game

optionsGroup = new ButtonGroup();


optionsGroup.add(option1);
optionsGroup.add(option2);
optionsGroup.add(option3);
optionsGroup.add(option4);

JPanel optionsPanel = new JPanel(new GridLayout(4, 1));


optionsPanel.add(option1);
optionsPanel.add(option2);
optionsPanel.add(option3);
optionsPanel.add(option4);

nextButton = new JButton("Next");


nextButton.addActionListener(e -> loadNextQuestion());

JPanel bottomPanel = new JPanel();


bottomPanel.add(nextButton);

frame.add(questionLabel, BorderLayout.NORTH);
frame.add(optionsPanel, BorderLayout.CENTER);
frame.add(bottomPanel, BorderLayout.SOUTH);

frame.setVisible(true);
}

private void loadQuestions() {


try {
PreparedStatement stmt = connection.prepareStatement("SELECT * FROM questions",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
questions = stmt.executeQuery();
questions.beforeFirst();
loadNextQuestion();
} catch (SQLException e) {
e.printStackTrace();
}
}

private void loadNextQuestion() {


try {
if (questions.isAfterLast()) {
return;
}

if (currentQuestionIndex > 1) {

Computer Engineering 2024-25 Page | 25


Rajiv Gandhi Polytechnic, Udgir Quiz game

// Check if the selected answer is correct


String selected = null;
if (option1.isSelected()) selected = option1.getText();
if (option2.isSelected()) selected = option2.getText();
if (option3.isSelected()) selected = option3.getText();
if (option4.isSelected()) selected = option4.getText();

if (selected != null && selected.equals(correctAnswer)) {


correctAnswers++;
}
}

if (questions.next()) {
questionLabel.setText("Q" + currentQuestionIndex + ": " + questions.getString("question"));
option1.setText(questions.getString("option1"));
option2.setText(questions.getString("option2"));
option3.setText(questions.getString("option3"));
option4.setText(questions.getString("option4"));
correctAnswer = questions.getString("option" + questions.getInt("correct_option"));
optionsGroup.clearSelection();
currentQuestionIndex++;
totalQuestions++;
} else {
saveScoreToDatabase();
JOptionPane.showMessageDialog(frame, "Quiz completed! Your score: " + correctAnswers +
"/" + totalQuestions);
frame.dispose();
new QuizSystem();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

private void saveScoreToDatabase() {

try {
String insertQuery = "INSERT INTO scores (username, score, total, date_taken) VALUES (?, ?, ?,
NOW())";

Computer Engineering 2024-25 Page | 26


Rajiv Gandhi Polytechnic, Udgir Quiz game

PreparedStatement stmt = connection.prepareStatement(insertQuery);


stmt.setString(1, username);

stmt.setInt(2, correctAnswers);
stmt.setInt(3, totalQuestions);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}

Computer Engineering 2024-25 Page | 27


Rajiv Gandhi Polytechnic, Udgir Quiz game

3. Quiz system

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

public class QuizSystem {


private JFrame frame;
private JTextField usernameField;
private JPasswordField passwordField;
private Connection connection;

public QuizSystem() {
connectToDatabase();
createLoginGUI();
}

private void connectToDatabase() {


try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/quizgame", "root",
"abhi@123");
System.out.println("Database connected successfully!");
} catch (SQLException e) {
JOptionPane.showMessageDialog(frame, "Database Connection Failed!", "Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
System.exit(0);
}
}

private void createLoginGUI() {


frame = new JFrame("Quiz Game - Login");
frame.setSize(420, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

JPanel panel = new JPanel();


panel.setLayout(null);
panel.setBackground(new Color(44, 62, 80));

JLabel titleLabel = new JLabel("Quiz Game Login", JLabel.CENTER);


titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
titleLabel.setForeground(Color.WHITE);
titleLabel.setBounds(100, 20, 200, 30);

JLabel userLabel = new JLabel("Username:");


userLabel.setForeground(Color.WHITE);

Computer Engineering 2024-25 Page | 28


Rajiv Gandhi Polytechnic, Udgir Quiz game

userLabel.setBounds(50, 80, 80, 25);

usernameField = new JTextField();


usernameField.setBounds(140, 80, 200, 30);

JLabel passLabel = new JLabel("Password:");


passLabel.setForeground(Color.WHITE);
passLabel.setBounds(50, 130, 80, 25);

passwordField = new JPasswordField();


passwordField.setBounds(140, 130, 200, 30);

JButton loginButton = new JButton("Login");


loginButton.setBounds(140, 180, 100, 35);
loginButton.addActionListener(e -> login());

JButton registerButton = new JButton("Register");


registerButton.setBounds(250, 180, 90, 35);
registerButton.addActionListener(e -> newUserRegistration());

JButton exitButton = new JButton("Exit");


exitButton.setBounds(140, 230, 200, 35);
exitButton.setBackground(new Color(231, 76, 60));
exitButton.setForeground(Color.WHITE);
exitButton.addActionListener(e -> System.exit(0));

panel.add(titleLabel);
panel.add(userLabel);
panel.add(usernameField);
panel.add(passLabel);
panel.add(passwordField);
panel.add(loginButton);
panel.add(registerButton);
panel.add(exitButton);

frame.add(panel);
frame.setVisible(true);
}

private void login() {


String username = usernameField.getText();
String password = new String(passwordField.getPassword());

if (username.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(frame, "Please enter both username and password!",
"Warning", JOptionPane.WARNING_MESSAGE);
return;
}

try {
String query = "SELECT role FROM users WHERE username = ? AND password = ?";
Computer Engineering 2024-25 Page | 29
Rajiv Gandhi Polytechnic, Udgir Quiz game

PreparedStatement stmt = connection.prepareStatement(query);


stmt.setString(1, username);
stmt.setString(2, password);
ResultSet rs = stmt.executeQuery();

if (rs.next()) {
String role = rs.getString("role");
frame.dispose();

if (role.equals("admin")) {
openAdminPanel(username);
} else {
openUserPanel(username);
}
} else {
JOptionPane.showMessageDialog(frame, "Invalid Username or Password!", "Error",
JOptionPane.ERROR_MESSAGE);
}
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(frame, "Login Error!", "Error", JOptionPane.ERROR_MESSAGE);
}
}

private void newUserRegistration() {


frame.dispose();
new RegistrationForm();
}

private void openAdminPanel(String username) {


new AdminPanel();
}

private void openUserPanel(String username) {


new QuestionPanel(username, connection);
}

public static void main(String[] args) {


new QuizSystem();
}
}

class RegistrationForm {
private JFrame frame;
private JTextField usernameField;
private JPasswordField passwordField;
private Connection connection;

public RegistrationForm() {
connectToDatabase();
createRegistrationGUI();
Computer Engineering 2024-25 Page | 30
Rajiv Gandhi Polytechnic, Udgir Quiz game

private void connectToDatabase() {


try {
String url = "jdbc:mysql://localhost:3306/quizgame";
String user = "root";
String pass = "abhi@123";
connection = DriverManager.getConnection(url, user, pass);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Database Connection Failed!", "Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}

private void createRegistrationGUI() {


frame = new JFrame("User Registration");
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);

JPanel panel = new JPanel();


panel.setLayout(null);

JLabel userLabel = new JLabel("Username:");


userLabel.setBounds(50, 50, 100, 25);

usernameField = new JTextField();


usernameField.setBounds(150, 50, 180, 30);

JLabel passLabel = new JLabel("Password:");


passLabel.setBounds(50, 100, 100, 25);

passwordField = new JPasswordField();


passwordField.setBounds(150, 100, 180, 30);

JButton registerButton = new JButton("Register");


registerButton.setBounds(150, 150, 100, 35);
registerButton.addActionListener(e -> registerUser());

panel.add(userLabel);
panel.add(usernameField);
panel.add(passLabel);
panel.add(passwordField);
panel.add(registerButton);

frame.add(panel);
frame.setVisible(true);
}

private void registerUser() {


String username = usernameField.getText();
Computer Engineering 2024-25 Page | 31
Rajiv Gandhi Polytechnic, Udgir Quiz game

String password = new String(passwordField.getPassword());

if (username.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(frame, "Fields cannot be empty!", "Warning",
JOptionPane.WARNING_MESSAGE);
return;
}

try {
String query = "INSERT INTO users (username, password, role) VALUES (?, ?, 'user')";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, username);
stmt.setString(2, password);
stmt.executeUpdate();
JOptionPane.showMessageDialog(frame, "Registration Successful!");
frame.dispose();
new QuizSystem();
} catch (SQLException e) {
JOptionPane.showMessageDialog(frame, "Username already exists!", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
}

Computer Engineering 2024-25 Page | 32


Rajiv Gandhi Polytechnic, Udgir Quiz game

10.2 Snapshots
Login Page:-

Computer Engineering 2024-25 Page | 33


Rajiv Gandhi Polytechnic, Udgir Quiz game

User Registration pages:-

Updated Registration pages:-

Admin pages:-
Computer Engineering 2024-25 Page | 34
Rajiv Gandhi Polytechnic, Udgir Quiz game

Updated Admin page:-

Computer Engineering 2024-25 Page | 35


Rajiv Gandhi Polytechnic, Udgir Quiz game

Question pages :-

Computer Engineering 2024-25 Page | 36


Rajiv Gandhi Polytechnic, Udgir Quiz game

Exam result table:-


Computer Engineering 2024-25 Page | 37
Rajiv Gandhi Polytechnic, Udgir Quiz game

Computer Engineering 2024-25 Page | 38


Rajiv Gandhi Polytechnic, Udgir Quiz game

11 .Conclusion

Computer Engineering 2024-25 Page | 39


Rajiv Gandhi Polytechnic, Udgir Quiz game

12 BIBILIOGRAPGY

 BOOKS
 Guidance of Teachers
 www.Openai.com
 www.blackbox.com
 www.google.com
 www.wikipedia.com
 www.techterms.com
 www.academia.com
 https://www.proprofs.com/quiz-school/topic/jee-exam
 https://www.jeefocus.com/
 https://www.quizrr.in/

Computer Engineering 2024-25 Page | 40

You might also like