Java
Java
on
“QUIZ USING BASIC JAVA”
Submitted for Partial Fulfillment of the Requirements
Bachelor of Technology
in
by
Ms. N SWAPNA
Assistant Professor
2022-23
i
DEPARTMENT OF ELECTRONICS & COMPUTER
ENGINEERINGSREENIDHI INSTITUTE OF SCIENCE &
TECHNOLOGY (AUTONOMOUS)
CERTIFICATE
This is to certify that the Project work entitled “Quiz using Basic Java”,
submitted by Jitta Yashwanth Reddy, Ratnala Sai Ganesh, Y Mohana Laxmi
bearing Roll No. 21311A1975, 21311A1976, 21311A1977 towards partial
fulfilment for the award of Bachelor Degree in Electronics & Computer Engineering from
Sreenidhi Institute of Science & Technology, Ghatkesar, Hyderabad, is a record of
bonafide workdone by him/ her. The results embodied in the work are not submitted to any
other University or Institutefor award of any degree or diploma.
(iii
)
DECLARATION
This is to certify that the work reported in the present Project Work titled “Quiz using Basic
Java” is a record work done by us in the Department of Electronics and Computer
Engineering, Sreenidhi Institute of Science and Technology, Yamnampet,Ghatkesar.
The report is based on the project work done entirely by us and not copied from any other
source.
(iii
)
ACKNOWLEDGMENT
We would like to express our sincere appreciation to everyone who supported us in completing
this project. Firstly, we extend our gratitude to Ms. N Swapna, Assistant Professor, who served
as our guide and provided us with valuable guidance, support, and timely suggestions throughout
the project.
We are grateful to Dr. D. Mohan, Head of the ECM Department at Sreenidhi Institute of Science
and Technology, Ghatkesar, for his encouragement and valuable suggestions that helped us
undertake this project. We would also like to thank Dr. T.Ch. Siva Reddy, Principal, and Mr.
C.V. Tommy, Executive Director, for their support throughout the project.
Finally, we would like to extend our thanks to our families, friends, and the teaching and non-
teaching staff who helped us directly or indirectly in this endeavor. We are grateful for their
constant support and encouragement.
(iv)
ABSTRACT
This abstract provides an overview of a quiz application developed using basic Java
programming concepts. The application aims to facilitate the creation and administration
of quizzes, allowing users to test their knowledge in various subjects. The quiz application
employs object-oriented programming principles and incorporates fundamental Java
features such as classes, inheritance, and polymorphism. It utilizes a console-based
interface to interact with the user, providing a straightforward and intuitive experience.
Furthermore, the quiz application includes functionalities for quiz management. It allows
users to create, edit, and delete quizzes, as well as add or remove questions from existing
quizzes. The application stores quiz data in a file or database, ensuring persistent storage
and easy retrieval of quiz information.
(v)
TABLE OF CONTENTS
LIST OF FIGURES
(viii)
CHAPTER 1
DESCRIPTION
This project is all about a quiz which is developed using basic Java programming like if, else
statements. This is the program of quiz game which test our IQ. First statement for greeting (Welcome).
Asking for interest if player text "yes" i.e., only start. If player text "no" i.e., quit & end the game.
Initial score is equal to zero before starting answering the given questions. Display questions from 1 to
10. For every question this Java program automatically checks if the player entered answer is correct
or not if it corrects i.e., display correct else display in correct. If and only if player answer is correct
i.e., only score will be incremented else no change in score (no-negative percentage). After completing
all the 10 questions it displays how many questions do you attempt correctly out of 10 and also display
over-all percentage. Final statement ends with thanks greeting.
The application enables users to create multiple-choice quizzes with customizable questions and
answer options. It supports a wide range of question types, including true/false, multiple-choice, and
fill-in-the-blank. Each quiz can have a predefined number of questions and can be assigned a time limit
for completion. To enhance user engagement, the quiz application includes features like scoring and
feedback. After completing a quiz, users receive an immediate score and feedback on their
performance. The application also offers the option to review answers and see correct solutions for
each question.
Furthermore, the quiz application includes functionalities for quiz management. It allows users to
create, edit, and delete quizzes, as well as add or remove questions from existing quizzes. The
application stores quiz data in a file or database, ensuring persistent storage and easy retrieval of quiz
information.
1
CHAPTER 2
2
2.3 PROGRAM
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Project7567 extends JFrame {
private JLabel questionLabel;
private JLabel headingLabel;
private JLabel textLabel;
private JTextField answerField;
private JButton submitButton;
private int score;
private String [] [] questions = {
{"What is the name of the Java compiler?", "javac"},
{"Which keyword is used to define a method that does not return any value in Java?",
"void"},
{"Which Java keyword is used to define a subclass of a class?", "extend"},
{"Dancing Java program is known as?", "swing"},
{"What is the name of the method that gets automatically invoked when an object is
created?", "constructor"},
{"What do you call a group of Java developers?", "array"},
{"What is JVM?", "platform"},
{"What is the process of combining multiple classes into one called?",
"inheritance"},
{"Which keyword is used to handle exceptions in Java?", "try"},
{"What is the keyword used to declare a variable that won't change its value?",
"final"}
};
private int currentQuestionIndex;
public Project7567() {
super("Quiz");
headingLabel = new JLabel ("Welcome to the Quiz");
headingLabel.setFont(new Font ("Arial", Font. BOLD, 20));
questionLabel = new JLabel ();
answerField = new JTextField (20);
submitButton = new JButton("Submit");
textLabel = new JLabel ("Done by J. Yashwanth Reddy, R. SaiGanesh, Y. Mohana
Laxmi");
textLabel.setFont(new Font ("Times New Roman", Font.ITALIC, 10));
score = 0;
currentQuestionIndex = 0;
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.CENTER;
panel.add(headingLabel, gbc);
gbc.gridy = 1;
gbc.gridwidth = 2;
panel.add(questionLabel, gbc);
3
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel.add(answerField, gbc);
gbc.gridy = 3;
gbc.gridwidth = 2;
panel.add(submitButton, gbc);
gbc.gridy = 4;
gbc.gridwidth = 2;
panel.add(textLabel, gbc);
add(panel);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
checkAnswer();
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setVisible(true);
showNextQuestion();
}
private void showNextQuestion() {
if (currentQuestionIndex < questions.length) {
questionLabel.setText(questions[currentQuestionIndex][0]);
answerField.setText("");
} else {
showResult();
}
}
private void checkAnswer() {
String userAnswer = answerField.getText();
if (userAnswer.equalsIgnoreCase(questions[currentQuestionIndex][1])) {
score++;
}
currentQuestionIndex++;
showNextQuestion();
}
private void showResult() {
double percentage = (score / (double) questions.length) * 100;
JOptionPane.showMessageDialog(this, "You got " + score + " questions correct\n" +
"You got " + percentage + "%");
System.exit(0);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Project7567();
}
});
}
}
4
2.4 IMPLEMENTATION
2.5 LIMITATIONS
➢ The solutions to the questions in the quiz may be not actually know to the users.
➢ The programmer needs to have code the program without any syntax or logical errors.
➢ The users have no option to clear their response once they have submitted or entered the
answer to the question.
➢ The users cannot see the remaining questions without completing the recent question.
➢ The previous answers cannot be changed.
5
CHAPTER 3
6
Figure 3.4 Result 4
7
Figure 3.7 Result 7
8
Figure 3.10 Result 10
9
CHAPTER 4
6.1 CONCLUSION
From this project one can understand the basic operations used in the Java programming.
Using those basic we can build a program. This is the project is basically a basic quiz which
is developed using if, else conditions and doing mathematical calculations for the average
score.
10
REFERENCES
[1] How do you create a simple quiz in Java? (n.d.). Quora. https://www.quora.com/How-do-
you-create-a-simple-quiz-in-Java
[2] Garcia, C. (2023). Simple Quiz Application In Java With Source Code. Source Code &
Projects. https://code-projects.org/simple-quiz-application-in-java-with-source-code/
11