import java.util.
Scanner;
public class QuizGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Questions, options, and correct answers
String[] questions = {
"1. What is the capital of France?",
"2. Which planet is known as the Red Planet?",
"3. Who wrote 'Romeo and Juliet'?",
"4. What is the largest ocean on Earth?",
"5. What is the chemical symbol for water?"
};
String[][] options = {
{"A. Paris", "B. London", "C. Berlin", "D. Madrid"},
{"A. Earth", "B. Mars", "C. Venus", "D. Jupiter"},
{"A. William Blake", "B. Mark Twain", "C. William Shakespeare", "D. Charles Dickens
{"A. Atlantic", "B. Indian", "C. Arctic", "D. Pacific"},
{"A. H2O", "B. CO2", "C. O2", "D. H2"}
};
char[] answers = {'A', 'B', 'C', 'D', 'A'}; // correct answers
int score = 0;
// Loop through questions
for (int i = 0; i < questions.length; i++) {
System.out.println(questions[i]);
for (String option : options[i]) {
System.out.println(option);
}
System.out.print("Enter your answer (A, B, C, or D): ");
char userAnswer = Character.toUpperCase(scanner.next().charAt(0));
// Compare input using if and switch
switch (userAnswer) {
case 'A':
case 'B':
case 'C':
case 'D':
if (userAnswer == answers[i]) {
score++;
}
break;
default:
System.out.println("Invalid input. Question skipped.");
}
System.out.println();
}
// Calculate and display percentage
double percentage = ((double) score / questions.length) * 100;
System.out.println("You got " + score + " out of " + questions.length + " correct.");
System.out.println("Your score: " + percentage + "%");
scanner.close();
}
}