1  import java.util.ArrayList;
  2  import java.util.Scanner;
  3  
  4  /**
  5     A quiz contains a list of questions.
  6  */
  7  public class Quiz
  8  {
  9     private ArrayList<Question> questions;
 10     
 11     /**
 12        Constructs a quiz with no questions.
 13     */
 14     public Quiz()
 15     {
 16        questions = new ArrayList<Question>();
 17     }
 18  
 19     /**
 20        Adds a question to this quiz.
 21        @param q the question
 22     */
 23     public void addQuestion(Question q)
 24     {
 25        questions.add(q);
 26     }
 27  
 28     /**
 29        Presents the questions to the user and checks the response.
 30     */
 31     public void presentQuestions()
 32     {
 33        Scanner in = new Scanner(System.in);
 34  
 35        for (Question q : questions)
 36        {
 37           q.display();
 38           System.out.print("Your answer: ");
 39           String response = in.nextLine();
 40           System.out.println(q.checkAnswer(response));
 41        }
 42     }
 43  }
 44