Created
March 20, 2016 20:51
-
-
Save AnEmortalKid/8f69b45948c60faabcaa to your computer and use it in GitHub Desktop.
The quiz displayer class
This file contains hidden or 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 void 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()); | |
| // this is what we'll output if the question is correct or not | |
| String correctText = "yes"; | |
| if(!correct) | |
| { | |
| correctText = "no"; | |
| } | |
| System.out.println("Is the answer correct? " + correctText); | |
| } | |
| 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); | |
| displayQuestion(first); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment