Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. public class Question {
  2.  
  3. private String question;
  4. private String option1;
  5. private String option2;
  6. private String option3;
  7. private String answer;
  8.  
  9. Question(String question, String option1, String option2, String option3, String answer) {
  10. this.question = question;
  11. this.option1 = option1;
  12. this.option2 = option2;
  13. this.option3 = option3;
  14. this.answer = answer;
  15. }
  16.  
  17. public String getQuestion() {
  18. return question;
  19. }
  20.  
  21. public String getOption1() {
  22. return option1;
  23. }
  24.  
  25. public String getOption2() {
  26. return option2;
  27. }
  28.  
  29. public String getOption3() {
  30. return option3;
  31. }
  32.  
  33. public String getAnswer() {
  34. return answer;
  35. }
  36. }
  37.  
  38. ------------------------------------------------------------------------
  39.  
  40. import java.util.ArrayList;
  41.  
  42. class QuestionBuilder {
  43.  
  44. static ArrayList<Question> questions() {
  45.  
  46. ArrayList<Question> questions = new ArrayList<>();
  47.  
  48. //lets add some questions to the question array list...
  49.  
  50. questions.add(new Question("Elon Musk is the CEO of which company?", "SpaceX", "Boston Dyamics", "Google", "SpaceX"));
  51. questions.add(new Question("Larry Page and Sergey Brin are the founders of?", "Apple", "Microsoft", "Google", "Google"));
  52. questions.add(new Question("Google's annual developers conference is called?", "Google IO", "Google 365", "Google Con", "Google IO"));
  53.  
  54. //now return the populated list...
  55. return questions;
  56. }
  57. }
  58.  
  59. ----------------------------------------------------------------------------------------
  60.  
  61. import android.support.v7.app.AppCompatActivity;
  62. import android.os.Bundle;
  63.  
  64. import java.util.ArrayList;
  65.  
  66. public class MainActivity extends AppCompatActivity {
  67.  
  68. private ArrayList<Question> questions;
  69.  
  70. private String question, opt1, opt2, opt3, answer;
  71.  
  72. @Override
  73. protected void onCreate(Bundle savedInstanceState) {
  74. super.onCreate(savedInstanceState);
  75. setContentView(R.layout.activity_main);
  76.  
  77. //lets populate the questions ArrayList with all of the
  78. //questions from the question builder class...
  79.  
  80. questions = QuestionBuilder.questions();
  81.  
  82. //now we can iterate the ArrayList using a loop and grab the info for each
  83. // question...
  84.  
  85. for (int i = 0; i < questions.size(); i++) {
  86. question = questions.get(i).getQuestion();
  87. opt1 = questions.get(i).getOption1();
  88. opt2 = questions.get(i).getOption2();
  89. opt3 = questions.get(i).getOption2();
  90. answer = questions.get(i).getAnswer();
  91. }
  92. }
  93. }
Add Comment
Please, Sign In to add comment