Modify the previous program below, Upload one document to the submission area that includes the following:

Words: 531
Pages: 2
Subject: Uncategorized

assignment in upload , Modify the previous program below, Upload one document to the submission area that includes the following:
QuestionDialog.java
Question.java
TrueFalseQuestion.java
MultipleChoiceQuestion.java
A screenshot showing a dialog box asking a true/false question
A screenshot showing a dialog box asking a multiple-choice question

Import javax.swing.JOptionPane;

public class MultipleChoiceQuestion extends Question{
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();
}

@Override
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;
else {
JOptionPane.showMessageDialog(null,”Invalid answer. Please enter A, B, C, D, or E.”);
}
}
}

}
import javax.swing.JOptionPane;

public abstract class Question {
static int nQuestions = 0;
static int nCorrect = 0;
String question;
String correctAnswer;
abstract String ask();
void check() {
nQuestions++;
String answer = ask();
if(answer.equals(correctAnswer)) {
JOptionPane.showMessageDialog(null,”Correct”);
nCorrect++;
}
else {
JOptionPane.showMessageDialog(null,”Incorrect. The correct answer is “+correctAnswer+”.”);}
}
static void showResults() {
JOptionPane.showMessageDialog(null,nCorrect+” correct out of”+nQuestions+”questions”);
}
}
public class Quiz {

public static void main(String[] args) {
Question question = new TrueFalseQuestion(“: Coding is fun!”,”y”);
question.check();
question = new TrueFalseQuestion(“: Programming is more fun than coding!”,”y”);
question.check();
question = new TrueFalseQuestion(“: Africa is a developing continent.”,”t”);
question.check();
question = new TrueFalseQuestion(“: Russia is invading Ukraine.”,”t”);
question.check();
question = new TrueFalseQuestion(“: Russia will suffer after the UN sactions.”,”t”);
question.check();
question = new MultipleChoiceQuestion(“How many countries are Africa?”,
“34.”,
“20.”,
“45.”,
“54.”,
“33.”,
“d”);
question.check();
MultipleChoiceQuestion question1 = new MultipleChoiceQuestion(“How many countries are there in the whole world?”,
“300.”,
“250”,
“195”,
“150”,
“100”,
“c”);
question1.check();
MultipleChoiceQuestion question2 = new MultipleChoiceQuestion(“How many days does it take for the Earth to orbit the Sun?”,
“365.”,
“185.”,
“225.”,
“196.”,
“128.”,
“a”);
question2.check();
MultipleChoiceQuestion question3 = new MultipleChoiceQuestion(“How many days in Feb in a leap year?”,
“28.”,
“29.”,
“30.”,
“31.”,
“27.”,
“b”);
question3.check();
MultipleChoiceQuestion question4 = new MultipleChoiceQuestion(“How many states does US have?”,
“54.”,
“56.”,
“53.”,
“50.”,
“51.”,
“d”);
question4.check();

}

}
import javax.swing.JOptionPane;

public class TrueFalseQuestion extends Question{
TrueFalseQuestion(String question, String answer){
this.question = “TRUE or FALSE” +question;
answer =answer.toUpperCase();
if(answer.equals(“T”)||answer.equals(“True”)||answer.equals(“Y”)||answer.equals(“YES”))
correctAnswer = “TRUE”;
if(answer.equals(“F”)||answer.equals(“FALSE”)||answer.equals(“N”)||answer.equals(“NO”))
correctAnswer = “FALSE”;
}

@Override
String ask() {
while(true) {
String answer =JOptionPane.showInputDialog(question);
answer =answer.toUpperCase();
if (answer.equals(“T”)|| answer.equals(“Y”) || answer.equals(“YES”))
answer = “TRUE”;
if (answer.equals(“F”)|| answer.equals(“N”) || answer.equals(“NO”))
answer = “FALSE”;
boolean valid = (answer.equals(“FALSE”)|| answer.equals(“TRUE”));
if(valid)
return answer;
else {
JOptionPane.showMessageDialog(null,”Invalid answer. Please enter TRUE or FALSE.”);
}
}
}
}

Let Us write for you! We offer custom paper writing services Order Now.

REVIEWS


Criminology Order #: 564575

“ This is exactly what I needed . Thank you so much.”

Joanna David.


Communications and Media Order #: 564566
"Great job, completed quicker than expected. Thank you very much!"

Peggy Smith.

Art Order #: 563708
Thanks a million to the great team.

Harrison James.


"Very efficient definitely recommend this site for help getting your assignments to help"

Hannah Seven