package xmp_question_noInheritance;

import java.util.ArrayList;

/**
   A question with multiple choices.
*/
public class ChoiceQuestion
{
   private String text;
   private String answer;
   private ArrayList<String> choices;

   /**
      Constructs a question with empty question and answer and no choices.
   */
   public ChoiceQuestion()
   {
      text = "";
      answer = "";
      choices = new ArrayList<String>();
   }

   /**
      Sets the question text.
      @param questionText the text of this question
   */
   public void setText(String questionText)
   {
      text = questionText;
   }

   /**
      Adds an answer choice to this question.
      @param choice the choice to add
      @param correct true if this is the correct choice, false otherwise
   */
   public void addChoice(String choice, boolean correct)
   {
      choices.add(choice);
      if (correct)
      {
         // Convert choices.size() to string
         String choiceString = "" + choices.size();
         setAnswer(choiceString);
      }
   }

   /**
      Sets the answer for this question.
      @param correctResponse the answer
   */
   public void setAnswer(String correctResponse)
   {
      answer = correctResponse;
   }

   /**
      Checks a given response for correctness.
      @param response the response to check
      @return true if the response was correct, false otherwise
   */
   public boolean checkAnswer(String response)
   {
      return response.equals(answer);
   }

   /**
      Displays this question.
   */
   public void display()
   {
      // Display the question text
      System.out.println(text);
      // Display the answer choices
      for (int i = 0; i < choices.size(); i++)
      {
         int choiceNumber = i + 1;
         System.out.println(choiceNumber + ": " + choices.get(i));
      }
   }
}
