The Java Online Quiz Project is an excellent beginner-to-intermediate Java project that demonstrates how to use classes, objects, methods, arrays, loops, conditional statements, and user input in a real-world application.
In this project, users can:
- View multiple-choice questions.
- Select answers.
- Automatically calculate their score.
- Display correct answers.
- Show pass/fail status.
- Display percentage.
This project is fully functional and can be copied directly into your Java IDE.
Project Features
- Console-based application
- Multiple-choice questions (MCQs)
- Automatic score calculation
- Percentage calculation
- Pass/Fail result
- Correct answer review
- Beginner-friendly code
- Easily extendable
Project Structure
JavaQuizProject
│
├── Question.java
└── QuizApp.java
File 1: Question.java
public class Question {
private String question;
private String optionA;
private String optionB;
private String optionC;
private String optionD;
private char correctAnswer;
public Question(String question,
String optionA,
String optionB,
String optionC,
String optionD,
char correctAnswer) {
this.question = question;
this.optionA = optionA;
this.optionB = optionB;
this.optionC = optionC;
this.optionD = optionD;
this.correctAnswer = Character.toUpperCase(correctAnswer);
}
public String getQuestion() {
return question;
}
public String getOptionA() {
return optionA;
pblic String getOptionB() {
return optionB;
}
public String getOptionC() {
return optionC;
}
public String getOptionD() {
return optionD;
}
public char getCorrectAnswer() {
return correctAnswer;
}
}
File 2: QuizApp.java
import java.util.Scanner;
public class QuizApp {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Question[] questions = {
new Question(
"1. Which language is platform independent?",
"A. C",
"B. Java",
"C. C++",
"D. Python",
'B'),
new Question(
"2. Which keyword is used to create an object?",
"A. object",
"B. class",
"C. new",
"D. create",
'C'),
new Question(
"3. Which method is the entry point of a Java program?",
"A. run()",
"B. execute()",
"C. start()",
"D. main()",
'D'),
new Question(
"4. Which package contains Scanner class?",
"A. java.io",
"B. java.util",
"C. java.lang",
"D. java.sql",
'B'),
new Question(
"5. Which loop always executes at least once?",
"A. for",
"B. while",
"C. do-while",
"D. foreach",
'C')
};
int score = 0;
char[] userAnswers = new char[questions.length];
System.out.println("==============================");
System.out.println(" JAVA ONLINE QUIZ");
System.out.println("==============================");
for (int i = 0; i = 60) {
System.out.println("Result : PASS");
} else {
System.out.println("Result : FAIL");
}
System.out.println();
System.out.println("==============================");
System.out.println("Correct Answers");
System.out.println("==============================");
for (int i = 0; i Your Answer: " + userAnswers[i] +
" | Correct Answer: " +
questions[i].getCorrectAnswer());
}
scanner.close();
}
}
Sample Output
==============================
JAVA ONLINE QUIZ
==============================
1. Which language is platform independent?
A. C
B. Java
C. C++
D. Python
Enter your answer (A/B/C/D): B
2. Which keyword is used to create an object?
A. object
B. class
C. new
D. create
Enter your answer (A/B/C/D): C
...
==============================
QUIZ RESULT
==============================
Total Questions : 5
Correct Answers : 4
Wrong Answers : 1
Percentage : 80.00%
Result : PASS
==============================
Correct Answers
==============================
Question 1 -> Your Answer: B | Correct Answer: B
Question 2 -> Your Answer: C | Correct Answer: C
Question 3 -> Your Answer: A | Correct Answer: D
Question 4 -> Your Answer: B | Correct Answer: B
Question 5 -> Your Answer: C | Correct Answer: C
How the Project Works
- The application creates an array of Question objects.
- Each object stores:
- Question text
- Four answer options
- Correct answer
- The quiz displays one question at a time.
- The user enters an option (A, B, C, or D).
- The application validates the input.
- If the answer is correct, the score increases.
- After all questions, the application displays:
- Total questions
- Correct answers
- Wrong answers
- Percentage
- Pass/Fail result
- Correct answer review
Features Implemented
- Object-Oriented Programming (OOP)
- Classes and Objects
- Constructors
- Arrays of Objects
- Encapsulation (Private Variables)
- Getters
- Scanner Class
- Loops
- Input Validation
- Percentage Calculation
- Pass/Fail Logic
- Result Summary
Possible Enhancements
You can extend this project by adding:
- Timer for each question
- Random question generation
- Reading questions from a text file, CSV, or database
- Difficulty levels (Easy, Medium, Hard)
- Negative marking
- User login and registration
- Leaderboard with high scores
- Category-wise quizzes (Java, Python, SQL, etc.)
- Graphical User Interface (GUI) using Swing or JavaFX
- Save quiz results to a file or database
- Review incorrect answers with explanations
Learning Outcomes
By building this project, you will learn:
- Java classes and objects
- Constructors
- Encapsulation
- Arrays of objects
- User input with Scanner
- Loops (for and while)
- Conditional statements (if-else)
- Input validation
- Percentage calculations
- Modular code organization
- Basic project structure
Conclusion
The Java Online Quiz Project is a practical project for beginners who want to apply core Java concepts in a real application. It combines object-oriented programming, user interaction, loops, arrays, and conditional logic into a clean, reusable solution. The code is modular, making it easy to add more questions, categories, timers, or persistent storage in future versions.
This project serves as a strong foundation for developing more advanced quiz systems with graphical interfaces, databases, web technologies, or REST APIs.