Advertisement
pastetumlum

Untitled

Jul 16th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. // model/QuestionLibrary.java
  2.  
  3. public class QuestionLibrary {
  4.     private int questionIndex;
  5.     private ArrayList<Question> questions;
  6.  
  7.     public QuestionLibrary() {
  8.         questionIndex = 0;
  9.         createLibrary();
  10.     }
  11.  
  12.     private void createLibrary() {
  13.         Library library = LibraryFactory.createLibrary();
  14.         questions = library.getLibrary();
  15.     }
  16.  
  17.     public ArrayList<Question> getQuestions() {
  18.         return questions;
  19.     }
  20.  
  21.     public int getQuestionIndex() {
  22.         return questionIndex;
  23.     }
  24.  
  25.     public void updateQuestionIndex() {
  26.         questionIndex = (questionIndex + 1) % questions.size();
  27.     }
  28.  
  29. }
  30.  
  31. // model/LibraryFactory.java
  32.  
  33. public class LibraryFactory {
  34.     public static Library createLibrary() {
  35.         return new SocialLibrary();
  36.     }
  37. }
  38.  
  39. // model/Library.java
  40.  
  41. public interface Library {
  42.     ArrayList<Question> getLibrary();
  43. }
  44.  
  45. // model/SocialLibrary.java
  46.  
  47. public class SocialLibrary implements Library {
  48.     public ArrayList<Question> getLibrary() {
  49.         ArrayList<Question> questions = new ArrayList<Question>();
  50.         Question question1 = new Question("Viet Nam co bao nhieu tinh thanh?", "62", "63", "64", "65", "b");
  51.         Question question2 = new Question("Thanh pho cua tinh Phu Yen", "Nha Trang", "Quy Nhon", "Tuy Hoa",
  52.                 "Mu Cang Chai", "c");
  53.         Question question3 = new Question("2018 la nam con gi?", "Cho", "Ga", "Bo", "Khi", "a");
  54.         Question question4 = new Question("1+1=", "3", "4", "2", "Tat ca deu sai", "c");
  55.         Question question5 = new Question("Ten game ban dang choi la gi?", "Find The Dog", "Find The Fish",
  56.                 "Find The Honey", "Honey The Find", "c");
  57.         questions.add(question1);
  58.         questions.add(question2);
  59.         questions.add(question3);
  60.         questions.add(question4);
  61.         questions.add(question5);
  62.         return questions;
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement