Class TrueFalseQuestion

java.lang.Object
Question
TrueFalseQuestion

public class TrueFalseQuestion
extends Question
A TrueFalseQuestion has either a true or false answer.
  • Constructor Summary

    Constructors
    Constructor Description
    TrueFalseQuestion​(java.lang.String prompt, boolean answer)
    Constructs a TrueFalseQuestion 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 TrueFalseQuestion's expected answer.
    java.lang.String getPrompt()
    Returns the prompt for this Question prefixed with the text: "True or false: ".

    Methods inherited from class Question

    getAnswer, toString

    Methods inherited from class java.lang.Object

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

    • TrueFalseQuestion

      public TrueFalseQuestion​(java.lang.String prompt, boolean answer)
      Constructs a TrueFalseQuestion 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 TrueFalseQuestion's expected answer. This method will consider any of the following values (case-insensitive) to be true:
      • T
      • True
      • Y
      • Yes

      All other values will be considered false.

      Overrides:
      checkAnswer in class Question
      Parameters:
      answer - the user's answer
      Returns:
      true if the user's answer is correct, false otherwise
    • getPrompt

      public java.lang.String getPrompt()
      Returns the prompt for this Question prefixed with the text: "True or false: ".
      Overrides:
      getPrompt in class Question
      Returns:
      String