Programming Assignment 1

You might also like

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

Programming Assignment 1

The quiz program with 5 questions is below:

import java.util.Scanner;

public class QuizGame {

public static void main(String[] args) {

Scanner stdin = new Scanner(System.in);

String answer1, answer2, answer3, answer4, answer5;

int score = 0;

// Question 1

System.out.println("Q1. What is the capital of Bangladesh?\nA. Kolkata\nB.

Dhaka\nC. Katmandu\nD. Sylhet");

answer1 = stdin.nextLine();

if (answer1.equals("B")) {

System.out.println("Correct answer");

score++;

} else {

System.out.println("Sorry, your answer is wrong.");

// Question 2

System.out.println("Q2. Which planet is known as the Red Planet?\nA. Venus\nB.

Mars\nC. Jupitar\nD. Saturn");


answer2 = stdin.nextLine();

if (answer2.equals("B")) {

System.out.println("Correct answer");

score++;

} else {

System.out.println("Sorry, your answer is wrong.");

// Question 3

System.out.println("Q3. Who wrote the play 'Romeo and Juliet'?\nA. William

Shakespeare\nB. Charles Dickens\nC. Jane Austen\nD. J.K. Rowling");

answer3 = stdin.nextLine();

if (answer3.equals("A")) {

System.out.println("Correct answer");

score++;

} else {

System.out.println("Sorry, your answer is wrong.");

// Question 4

System.out.println("Q4. What is the chemical symbol for water?\nA. H20\nB.

CO2\nC. O2\nD. NaCl");

answer4 = stdin.nextLine();

if (answer4.equals("A")) {
System.out.println("Correct answer");

score++;

} else {

System.out.println("Sorry, your answer is wrong.");

// Question 5

System.out.println("Q5. What is the largest mammal in the world?\nA. Elephant\

nB. Giraffe\nC. Blue Whale\nD. Lion");

answer5 = stdin.nextLine();

if (answer5.equals("C")) {

System.out.println("Correct answer");

score++;

} else {

System.out.println("Sorry, your answer is wrong.");

double percentage = (double) score / 5 * 100;

System.out.println("Your score: " + score + " out of 5");

System.out.println("Percentage: " + percentage + "%");

The output screen is shown below:

You might also like