0% found this document useful (0 votes)
18 views3 pages

CS1102 Unit 2

This Java code presents the user with a multiple choice quiz question about the location of Afghanistan. It displays the question and five answer options using a pop-up dialog box. It then checks the user's response, provides feedback on whether it is correct or incorrect, and repeats the process until the user selects the right answer of option A, which is that Afghanistan is located in Central Asia.

Uploaded by

Marwa Azizyar
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)
18 views3 pages

CS1102 Unit 2

This Java code presents the user with a multiple choice quiz question about the location of Afghanistan. It displays the question and five answer options using a pop-up dialog box. It then checks the user's response, provides feedback on whether it is correct or incorrect, and repeats the process until the user selects the right answer of option A, which is that Afghanistan is located in Central Asia.

Uploaded by

Marwa Azizyar
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
You are on page 1/ 3

import javax.swing.

JOptionPane;

public class QUIZ {

public static void main(String[] args) {

String question = "Where is Afganistan?\n";

question += "A. Afghanistan is located in Central Asia\n";

question += "B. Afghanistan is located in Central Europe\n";

question += "C. Afghanistan is located in Central Australia\n";

question += "D. Afghanistan is located in Japan\n";

question += "E. Afghanistan is located in USA\n";

while (5 >1) {

String answer = JOptionPane.showInputDialog(question);

System.out.println(answer);

answer = answer.toUpperCase();

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

JOptionPane.showMessageDialog(null,"Correct!");

break;

}else if (answer.equals("B")) {

JOptionPane.showMessageDialog(null,"Incorrect. Please try again.");

}else if (answer.equals("C")) {

JOptionPane.showMessageDialog(null,"Incorrect. Please try again.");

}else if (answer.equals("D")) {

JOptionPane.showMessageDialog(null,"Incorrect. Please try again.");

}else if (answer.equals("E")) {

JOptionPane.showMessageDialog(null,"Incorrect. Please try again.");

}else {

JOptionPane.showMessageDialog(null,"Invalid answer. Please enter A, B, C, D, or E.");

}
}

You might also like