Skip to content

Instantly share code, notes, and snippets.

@AnEmortalKid
Created March 20, 2016 21:05
Show Gist options
  • Save AnEmortalKid/87a2004ff943ecbcaeff to your computer and use it in GitHub Desktop.
Save AnEmortalKid/87a2004ff943ecbcaeff to your computer and use it in GitHub Desktop.
modified with two questions and displaying correct or not
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