0% found this document useful (0 votes)
6 views4 pages

Java Quiz Game Programming Assignment

The document presents a Java program for a quiz game created by student Musozi Marvin. It includes five questions with options, tracks correct answers, and calculates the final score as a percentage. Key features include input validation, use of control structures, and clear output formatting.

Uploaded by

musozi marvin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Java Quiz Game Programming Assignment

The document presents a Java program for a quiz game created by student Musozi Marvin. It includes five questions with options, tracks correct answers, and calculates the final score as a percentage. Key features include input validation, use of control structures, and clear output formatting.

Uploaded by

musozi marvin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Assignment Unit 1

Student Name: Musozi Marvin


Instructor: Rajesh Soni

import [Link];

public class QuizGame {

public static void main(String[] args) {


Scanner scanner = new Scanner([Link]);
int correctAnswers = 0;

[Link]("Welcome to the Java Quiz Game!");


[Link]("------------------------------");

// Question 1
[Link]("Question 1: What is the capital of France?");
[Link]("A. London B. Berlin C. Paris D. Rome");
[Link]("Your answer: ");
String answer1 = [Link]().toUpperCase();
switch (answer1) {
case "C":
correctAnswers++;
break;
default:
break;
}

// Question 2

1
[Link]("\nQuestion 2: Which data type is used to create a variable that
should store text?");
[Link]("A. int B. String C. char D. float");
[Link]("Your answer: ");
String answer2 = [Link]().toUpperCase();
if ([Link]("B")) {
correctAnswers++;
}

// Question 3
[Link]("\nQuestion 3: Who developed Java?");
[Link]("A. Dennis Ritchie B. James Gosling C. Bjarne Stroustrup D.
Guido van Rossum");
[Link]("Your answer: ");
String answer3 = [Link]().toUpperCase();
switch (answer3) {
case "B":
correctAnswers++;
break;
default:
break;
}

// Question 4
[Link]("\nQuestion 4: What does JVM stand for?");
[Link]("A. Java Very Machine B. Java Variable Method");
[Link]("C. Java Virtual Machine D. Java Verified Mode");
[Link]("Your answer: ");
String answer4 = [Link]().toUpperCase();
if ([Link]("C")) {

2
correctAnswers++;
}

// Question 5
[Link]("\nQuestion 5: Which keyword is used to define a class in Java?");
[Link]("A. define B. create C. new D. class");
[Link]("Your answer: ");
String answer5 = [Link]().toUpperCase();
switch (answer5) {
case "D":
correctAnswers++;
break;
default:
break;
}

// Final Score Calculation


double scorePercent = (correctAnswers / 5.0) * 100;
[Link]("\nYou got " + correctAnswers + " out of 5 correct!");
[Link]("Final Score: " + scorePercent + "%");

[Link]();
}
}

3
Explanation of Key Features:
 Input Validation: Accepts A/B/C/D and converts to uppercase to reduce errors.
 Logic & Computation: Tracks correct answers and computes the percentage.
 Use of if and switch: Demonstrates both control structures.
 Clear Output: Questions are clearly formatted for readability.
 Comments: Comments are included inline to explain each part of the code (add more
if required for grading).

You might also like