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

Programming Assignment Unit 2 Sample 4

This Java code presents the user with a multiple choice quiz question asking which assignment type a piece of code represents. It displays the question and possible answers, reads the user's response, checks if it is correct, and provides feedback on the answer. The code will continue to loop, re-prompting until the user selects the correct option "C", or indicates an invalid answer.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

Programming Assignment Unit 2 Sample 4

This Java code presents the user with a multiple choice quiz question asking which assignment type a piece of code represents. It displays the question and possible answers, reads the user's response, checks if it is correct, and provides feedback on the answer. The code will continue to loop, re-prompting until the user selects the correct option "C", or indicates an invalid answer.
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