The document describes a Java quiz game program that asks multiple choice questions, tracks the user's score, and displays the final percentage. The program initializes questions and answers, gets user input, checks the responses, and calculates the score at the end.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
12 views
The Java Quiz Game
The document describes a Java quiz game program that asks multiple choice questions, tracks the user's score, and displays the final percentage. The program initializes questions and answers, gets user input, checks the responses, and calculates the score at the end.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
The Java Quiz Game
Code:
import java.util.Scanner;
public class JavaQuizGame {
public static void main(String[] args) {
// Initialize a Scanner for user input Scanner scanner = new Scanner(System.in);
// Define the quiz questions and correct answers
String[] questions = { "What is Uopeople university Located?", "Who is the instructor for programming 1102?", "How many units are there in CS-1102 course?", "Who is supposed to make sure assignments are updated?", };
char[] correctAnswers = {'C', 'B', 'A', 'D'};
// Initialize variables to track user score
int totalQuestions = questions.length; int correctResponses = 0;
// Display the quiz questions and get user input
for (int i = 0; i < totalQuestions; i++) { System.out.println("Question " + (i + 1) + ":\n " + questions[i]); System.out.println("\nA) Nine units"); System.out.println("B) Dr. Ursa Sayeed"); System.out.println("C) Pasadena , California"); System.out.println("D) The Student \n"); System.out.print("Your answer (A, B, C, or D): ");