Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Java Mini-Project

Quiz Game

Submitted by:
Ms. Aditi Pal - 266
Mr. Shabaz Ansari-
262
Ms. Pragya pal- 267
Ms. Sanghvi Raut- 269
Under the Guidance of
Prof: Kanchan
Talekar
Quiz Game
This Java program generate a random password of a specified length using a combination of
lowercase letters, uppercase letters, digits, and special characters. The generated password
is meant to be secure and suitable for various applications requiring strong authentication

Key Features:
Multiple topics :The user can select topics on which he/she wants to answer the topics from.
Correct answer :The correct answer is provided if you have answered incorrectly .
Unlimited tries : Even if u answer the questions incorrectly you can re-execute the code to get a fresh new
start.

How to Use:

Run the program.


Select the topic on which u want to attempt the quiz.

Answer the questions (correct answer will be displayed if you have answered incorrectly).

Also you repeat the execution if you want to attempt a different topic from the list.
Code:-

import java.util.Scanner;

public class OnlineQuizGame {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Welcome to the Online Quiz Game!");


System.out.println("Choose a category:");
System.out.println("1. General Knowledge");
System.out.println("2. Java Programming");

int categoryChoice = getUserChoice(scanner);

if (categoryChoice == 1) {
startGeneralKnowledgeQuiz();
} else if (categoryChoice == 2) {
startJavaProgrammingQuiz();
} else {
System.out.println("Invalid choice. Exiting the quiz.");
return;
}

// Close the Scanner to release resources


scanner.close();
}

private static int getUserChoice(Scanner scanner) {


while (!scanner.hasNextInt()) {
System.out.println("Invalid input. Please enter a number.");
scanner.next(); // Consume the invalid input
}
return scanner.nextInt();
}

private static void startGeneralKnowledgeQuiz() {


System.out.println("General Knowledge Quiz Started!");
// Add general knowledge questions and logic here
System.out.println("Question 1: What is the capital of France?");
String answer1 = "Paris";
String userAnswer1 = getUserInput();

if (userAnswer1.equalsIgnoreCase(answer1)) {
System.out.println("Correct!");
} else {
System.out.println("Incorrect. The correct answer is " + answer1);
}

// Add more questions as needed...


}

private static void startJavaProgrammingQuiz() {


System.out.println("Java Programming Quiz Started!");
// Add Java programming questions and logic here
System.out.println("Question 1: What is the main method's signature in Java?");
String answer1 = "public static void main(String[] args)";
String userAnswer1 = getUserInput();

if (userAnswer1.equals(answer1)) {
System.out.println("Correct!");
} else {
System.out.println("Incorrect. The correct answer is " + answer1);
}

// Add more questions as needed...


}

private static String getUserInput() {


Scanner scanner = new Scanner(System.in);
System.out.print("Your answer: ");
return scanner.nextLine();
}
}
Output :-

Conclusion:- This projects allows user to prepare a quiz for


students on multiple topics at a single instance of time, thereby
providing efficient time usage.

You might also like