import javax.swing.JOptionPane; public class MultipleChoiceQuestion { static int correct = 0; static int incorrect = 0; String question; String correctAnswer; MultipleChoiceQuestion(String query, String a, String b, String c, String d, String e, String Answer) { question = query+"\n"; question = "A. "+a+"\n"; question = "B. "+b+"\n"; question = "C. "+c+"\n"; question = "D. "+d+"\n"; question = "E. "+e+"\n"; correctAnswer = Answer.toUpperCase(); } String ask() { while (true) { String answer = JOptionPane.showInputDialog(question); answer =answer.toUpperCase(); } String ask() { while (true) { String answer = JOptionPane.showInputDialog(question); answer=answer.toUpperCase(); boolean valid = (answer.equals("A")||answer.equals("B")|| answer.equals("C")|| answer.equals("D")||answer.equals("E")); If(valid) return answer; JOptionPane.showMessageDialog(null,"Invalid answer. Please enter" A, B, C, D, or E."); } } void check() { nQuestions++; String answer = ask(); if (answer.equals(correctAnswer)) { JOptionPane.showMessageDialog(null,"Correct!"); int nCorrect = 0; nCorrect++; }else { JOptionPane.showMessageDialog(null,"Incorrect. The correct answer is + "+correctAnswer+"."); } } static void showResults() { Object nCorrect = null; Object nQuestions = null; JOptionPane.showMessageDialog(null,nCorrect +"correct out of "+ nQuestions +" questions"); } } public class Quiz { public static void main(String[] args) { MultipleChoiceQuestion question = new MultipleChoiceQuestion("What is a quiz?", "a test of knowledge, especially a brief informal test given to students", "42", "a duck", "to get to the other side", "To be or not to be, that is the question.", question.check(); question.showResults(); MultipleChoiceQuestion question1 = new MultipleChoiceQuestion("Who was the first president of the United States?", "Washington", "Jefferson", "Lincoln", "Clinton", "a"); question1.check(); question1.showResults(); MultipleChoiceQuestion question2 = new MultipleChoiceQuestion("The World Wide Web is also known?", "Digital Magician", "Information Age", "Internet", "Personal Computer", "c"); question2.check(); question2.showResults(); MultipleChoiceQuestion question3 = new MultipleChoiceQuestion("Buying and selling on the internet is called?", "Consumerism", "E-Commerce", "Globalization", "The Free Market", "b"); question3.check(); question3.showResults(); MultipleChoiceQuestion question4 = new MultipleChoiceQuestion("What does URL stand for?", "Universal Resource Locale", "Universal Reading Location", "Universal Resource Logistic", "Uniform Resource Locator", "d"); question4.check(); question4.showResults(); MultipleChoiceQuestion question5 = new MultipleChoiceQuestion("Data information is stored in the computer as ?", "Files", "Floppies", "Directories", "Processors", "a"); question5.check(); question5.showResults(); MultipleChoiceQuestion.showResults(); } private static MultipleChoiceQuestion question() { // TODO Auto-generated method stub return null; } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help me with my Java assignment.  I need to know why I can't seem to get rid of my bug errors and if I had indented wrong because I'm supposed to get my dialog box pop up and it doesn't even if I did overcame my bugs.  My assignment is below this message as follows:

 

import javax.swing.JOptionPane;

public class MultipleChoiceQuestion {
static int correct = 0;
static int incorrect = 0;
String question;
String correctAnswer;

MultipleChoiceQuestion(String query, String a, String b, String c, String d,
String e, String Answer) {
question = query+"\n";
question = "A. "+a+"\n";
question = "B. "+b+"\n";
question = "C. "+c+"\n";
question = "D. "+d+"\n";
question = "E. "+e+"\n";
correctAnswer = Answer.toUpperCase();

}

String ask() {
while (true) {
String answer = JOptionPane.showInputDialog(question);
answer =answer.toUpperCase();
}
String ask() {
while (true) {
String answer = JOptionPane.showInputDialog(question);
answer=answer.toUpperCase();
boolean valid = (answer.equals("A")||answer.equals("B")||
answer.equals("C")|| answer.equals("D")||answer.equals("E"));
If(valid) return answer;
JOptionPane.showMessageDialog(null,"Invalid answer. Please enter" A, B, C, D, or
E.");
}
}
void check() {
nQuestions++;
String answer = ask();
if (answer.equals(correctAnswer)) {
JOptionPane.showMessageDialog(null,"Correct!");
int nCorrect = 0;
nCorrect++;
}else {
JOptionPane.showMessageDialog(null,"Incorrect. The correct answer is + "+correctAnswer+".");
}
}
static void showResults() {
Object nCorrect = null;
Object nQuestions = null;
JOptionPane.showMessageDialog(null,nCorrect +"correct out of "+ nQuestions +" questions");

}

}
public class Quiz {
public static void main(String[] args) {
MultipleChoiceQuestion question = new MultipleChoiceQuestion("What is a quiz?",
"a test of knowledge, especially a brief informal test given to students",
"42",
"a duck",
"to get to the other side",
"To be or not to be, that is the question.",

question.check();
question.showResults();


MultipleChoiceQuestion question1 = new MultipleChoiceQuestion("Who was the first president of the United States?",
"Washington",
"Jefferson",
"Lincoln",
"Clinton",
"a");

question1.check();
question1.showResults();

MultipleChoiceQuestion question2 = new MultipleChoiceQuestion("The World Wide Web is also known?",
"Digital Magician",
"Information Age",
"Internet",
"Personal Computer",
"c");

question2.check();
question2.showResults();

MultipleChoiceQuestion question3 = new MultipleChoiceQuestion("Buying and selling on the internet is called?",
"Consumerism",
"E-Commerce",
"Globalization",
"The Free Market",
"b");

question3.check();
question3.showResults();

MultipleChoiceQuestion question4 = new MultipleChoiceQuestion("What does URL stand for?",
"Universal Resource Locale",
"Universal Reading Location",
"Universal Resource Logistic",
"Uniform Resource Locator",
"d");

question4.check();
question4.showResults();


MultipleChoiceQuestion question5 = new MultipleChoiceQuestion("Data information is stored in the computer as ?",
"Files",
"Floppies",
"Directories",
"Processors",
"a");

question5.check();
question5.showResults();

MultipleChoiceQuestion.showResults();
}

private static MultipleChoiceQuestion question() {
// TODO Auto-generated method stub
return null;
}



}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY