Created
May 5, 2015 01:12
-
-
Save witoong623/f03f206a315f4994dbce to your computer and use it in GitHub Desktop.
Demonstrate simple ask-question
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 Program implements ActionListener | |
// Store instance of Question clas in array | |
private Question[] question = new Question[30]; | |
// Maintain question index to indicate current question | |
private int CurrentQuestion; | |
........ | |
public Program() | |
{ | |
// instantiate question 1, assume answer is choice 2 | |
question[0] = new Question("This is question 1", | |
new String {"choice 1", "choice 2", "choice 3", "choice 4"}, | |
1); | |
..... do it to 30 | |
// Set current question index | |
CurrentQuestion = -1; | |
} | |
private void MoveNext() { | |
if (CurrentQuestion < question.Length) { | |
CurrentQuestion++; | |
} | |
else { | |
return; | |
} | |
// I assume every UI variables's name | |
// Question itself | |
Label.setText(question[CurrentQuestion].getQuestionText()); | |
// Button that indicate choice | |
Button1.setText(question[CurrentQuestion].getChoice()[0]); | |
..... do it to choice 4 | |
} | |
private void actionPerformed(ActionEvent e) | |
{ | |
if (e.getSource().getText().equals( | |
question[CurrentQuestion].getChoice()[question[CurrentQuestion].getAnswer()])) { | |
// user click correct answer | |
} | |
else { | |
// user click incorrect answer | |
} | |
} |
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 Question { | |
private string QuestionText; | |
private string[] Choice; | |
private int Answer; | |
public Quention(string question, string[] choice, int answer) { | |
QuestionText = question; | |
Choice = choice; | |
Answer = answer; | |
} | |
public string getQuestionText() { | |
return QuestionText; | |
} | |
public string[] getChoice() { | |
return Choice; | |
} | |
public int getAnswer() { | |
return Answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment