Unit 5 Programming Assignment Solution
Unit 5 Programming Assignment Solution
Unit 5 Programming Assignment Solution
The quiz questions, answers, and choices for correct answer should be unique for each submission. Here
is an example.
File "Question.java":
import javax.swing.JOptionPane;
String question;
String correctAnswer;
void check() {
nQuestions++;
if (answer.equals(correctAnswer)) {
JOptionPane.showMessageDialog(null,"Correct!");
nCorrect++;
} else {
}
File "TrueFalseQuestion.java".
import javax.swing.JOptionPane;
String ask() {
while (true) {
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";
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";
File "MultipleChoiceQuestion.java"
import javax.swing.JOptionPane;
public class MultipleChoiceQuestion extends Question {
question = query+"\n";
correctAnswer = answer.toUpperCase();
String ask() {
while (true) {
answer = answer.toUpperCase();
File "Quiz.java".
question.check();
question.check();
question.check();
question.check();
"What is a quiz?",
"42",
"a duck",
"a");
question.check();
"right now",
"nevermore",
"b");
question.check();
"right here",
"c");
question.check();
"Who is to say?",
"d");
question.check();
"fair to middling",
"not bad",
"by accident",
"e");
question.check();
question.showResults();
}