Package SolvishR
Class Question
java.lang.Object
SolvishR.Question
- Direct Known Subclasses:
AdditionQuestion,DivisionQuestion,MultiplicationQuestion,SubtractionQuestion
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcheckAnswer(String givenAnswer) Abstract method to check the provided answer.Gets the correct answer as a string.Gets the given answer as a string.booleanChecks if the question has been answered.booleanChecks if the given answer is correct.abstract voidshow()Abstract method to display the question.
-
Field Details
-
answer
public double answerThe correct answer to the question.
-
-
Constructor Details
-
Question
public Question()
-
-
Method Details
-
isCorrect
public boolean isCorrect()Checks if the given answer is correct.- Returns:
trueif the answer is correct within a tolerance of 0.01,falseotherwise.- Throws:
NullPointerException- If the answer is not a number.
-
isAnswered
public boolean isAnswered()Checks if the question has been answered.- Returns:
trueif the question has been answered,falseotherwise.
-
getGivenAnswer
Gets the given answer as a string.- Returns:
- The given answer as a string.
-
getCorrectAnswer
Gets the correct answer as a string.- Returns:
- The correct answer as a string.
-
checkAnswer
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.
-