0% found this document useful (0 votes)
31 views

Programming Assignment Unit 2 Sample 3

The document contains code for a Java quiz program that asks the user which assignment type a question is for and checks their answer. The program uses JOptionPane to display the question, get the answer, and show if the answer is correct or incorrect.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Programming Assignment Unit 2 Sample 3

The document contains code for a Java quiz program that asks the user which assignment type a question is for and checks their answer. The program uses JOptionPane to display the question, get the answer, and show if the answer is correct or incorrect.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import javax.swing.

JOptionPane;

public class Quiz{

public static void main(String[] args) {

String question = "Which assignment is this?\n";

question += "A. The discution Assignment\n";

question += "B. The Learning Journal\n";

question += "C. The Programming Assignment\n";

question += "D. The Reading Assignment\n";

question += "E. The Self Quiz\n";

while (true) {

String answer = JOptionPane.showInputDialog(question);

answer = answer.toUpperCase();

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

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

break;}

else if (answer.equals("A") || answer.equals("B") || answer.equals("D") || 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