Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Question {
- private String text;
- private String answer;
- public Question()
- {
- text = "";
- answer = "";
- }
- public void setText(String questionText)
- {
- text = questionText;
- }
- public void setAnswer(String correctResponse)
- {
- answer = correctResponse;
- }
- public boolean checkAnswer(String response)
- {
- return response.equals(answer);
- }
- public void display()
- {
- System.out.println(text);
- }
- public String toString()
- {
- return "Question[text=" + text + "]";
- }
- public String toString2()
- {
- return "Question[answer=" + answer + "]";
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- import java.util.ArrayList;
- public class ChoiceQuestion extends Question {
- private ArrayList<String> choices;
- public ChoiceQuestion()
- {
- choices = new ArrayList<String>();
- }
- public void addChoice(String choice, boolean correct)
- {
- choices.add(choice);
- if(correct)
- {
- String choiceString = "" + choices.size();
- setAnswer(choiceString);
- }
- }
- public void Display()
- {
- for(int i = 0; i < choices.size(); i++ )
- {
- super.display();
- int choiceNumber = i + 1;
- System.out.println(choiceNumber + ": " + choices.get(i));
- }
- }
- public String toString2()
- {
- return "Question[choices=" + choices + "]";
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement