Class Question

java.lang.Object
Question
Direct Known Subclasses:
MultipleChoiceQuestion, TrueFalseQuestion

public class Question
extends java.lang.Object
Parent class for all types of questions that may be asked in a Quiz. This default implementation represents a free response (i.e., "standard") question.
  • Constructor Summary

    Constructors
    Constructor Description
    Question​(java.lang.String prompt, java.lang.String answer)
    Constructs a Question with the given prompt and answer.
  • Method Summary

    Modifier and Type Method Description
    boolean checkAnswer​(java.lang.String answer)
    Checks if the user's answer matches this Question's expected answer, ignoring case.
    java.lang.String getAnswer()
    Returns the answer for this Question.
    java.lang.String getPrompt()
    Returns the prompt for this Question.
    java.lang.String toString()
    Returns the String representation of this Question.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Question

      public Question​(java.lang.String prompt, java.lang.String answer)
      Constructs a Question with the given prompt and answer.
      Parameters:
      prompt - the question's prompt
      answer - the question's answer
  • Method Details

    • checkAnswer

      public boolean checkAnswer​(java.lang.String answer)
      Checks if the user's answer matches this Question's expected answer, ignoring case.
      Parameters:
      answer - the user's answer
      Returns:
      true if the user's answer is correct, false otherwise
    • getAnswer

      public java.lang.String getAnswer()
      Returns the answer for this Question.
      Returns:
      String
    • getPrompt

      public java.lang.String getPrompt()
      Returns the prompt for this Question.
      Returns:
      String
    • toString

      public java.lang.String toString()
      Returns the String representation of this Question.
      Overrides:
      toString in class java.lang.Object
      See Also:
      Object.toString()