Created
March 20, 2016 21:05
-
-
Save AnEmortalKid/87a2004ff943ecbcaeff to your computer and use it in GitHub Desktop.
modified with two questions and displaying correct or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuizDisplayer { | |
private static boolean displayQuestion(Question question) { | |
int optionChosen = JOptionPane.showOptionDialog(null, question.getQuestion(), "Please Select", | |
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, question.getAnswerOptions(), | |
question.getAnswerOptions()[0]); | |
String answer = question.getAnswerOptions()[optionChosen]; | |
boolean correct = answer.equals(question.getCorrectAnswer()); | |
return correct; | |
} | |
public static void main(String[] args) { | |
String[] options = { "True", "False" }; | |
Question first = new Question("The first part of any method is its header.", "True", options); | |
boolean firstCorrect = displayQuestion(first); | |
System.out.println("First Correct: " + firstCorrect); | |
String[] q2Options = {"True", "False"}; | |
Question second = new Question("A line of code that declares a variable is known as a varibale declaration", "True", q2Options); | |
boolean secondCorrect = displayQuestion(second); | |
System.out.println("Second Correct:" + secondCorrect); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment