Advertisement
CyrusVerkest

E9.7

Nov 28th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class Question {
  2. private String text;
  3. private String answer;
  4. public Question()
  5. {
  6. text = "";
  7. answer = "";
  8. }
  9.  
  10. public void setText(String questionText)
  11. {
  12. text = questionText;
  13. }
  14.  
  15.  
  16. public void setAnswer(String correctResponse)
  17. {
  18. answer = correctResponse;
  19. }
  20.  
  21. public boolean checkAnswer(String response)
  22. {
  23. return response.equals(answer);
  24. }
  25.  
  26. public void display()
  27. {
  28. System.out.println(text);
  29. }
  30. public String toString()
  31. {
  32. return "Question[text=" + text + "]";
  33. }
  34. public String toString2()
  35. {
  36. return "Question[answer=" + answer + "]";
  37. }
  38. }
  39. -----------------------------------------------------------------------------------------------------------------------------------
  40. import java.util.ArrayList;
  41.  
  42.  
  43. public class ChoiceQuestion extends Question {
  44. private ArrayList<String> choices;
  45.  
  46. public ChoiceQuestion()
  47. {
  48. choices = new ArrayList<String>();
  49. }
  50.  
  51. public void addChoice(String choice, boolean correct)
  52. {
  53. choices.add(choice);
  54. if(correct)
  55. {
  56. String choiceString = "" + choices.size();
  57. setAnswer(choiceString);
  58. }
  59. }
  60.  
  61. public void Display()
  62. {
  63. for(int i = 0; i < choices.size(); i++ )
  64. {
  65. super.display();
  66. int choiceNumber = i + 1;
  67. System.out.println(choiceNumber + ": " + choices.get(i));
  68. }
  69. }
  70. public String toString2()
  71. {
  72. return "Question[choices=" + choices + "]";
  73. }
  74.  
  75. }
  76.  
  77. -----------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement