Package SolvishR

Class Question

java.lang.Object
SolvishR.Question
Direct Known Subclasses:
AdditionQuestion, DivisionQuestion, MultiplicationQuestion, SubtractionQuestion

public abstract class Question extends Object
The base class for representing a question. Subclasses must implement the abstract methods checkAnswer(String) and show(). Provides methods to check if an answer is correct, determine if the question has been answered, and retrieve the given and correct answers.
Version:
1.0
Author:
Adib Sakhawat
  • Field Details

    • answer

      public double answer
      The correct answer to the question.
  • Constructor Details

    • Question

      public Question()
  • Method Details

    • isCorrect

      public boolean isCorrect()
      Checks if the given answer is correct.
      Returns:
      true if the answer is correct within a tolerance of 0.01, false otherwise.
      Throws:
      NullPointerException - If the answer is not a number.
    • isAnswered

      public boolean isAnswered()
      Checks if the question has been answered.
      Returns:
      true if the question has been answered, false otherwise.
    • getGivenAnswer

      public String getGivenAnswer()
      Gets the given answer as a string.
      Returns:
      The given answer as a string.
    • getCorrectAnswer

      public String getCorrectAnswer()
      Gets the correct answer as a string.
      Returns:
      The correct answer as a string.
    • checkAnswer

      public abstract void checkAnswer(String givenAnswer)
      Abstract method to check the provided answer.
      Parameters:
      givenAnswer - The answer provided by the user.
    • show

      public abstract void show()
      Abstract method to display the question.