Class MultipleChoiceQuestion
java.lang.Object
Question
MultipleChoiceQuestion
public class MultipleChoiceQuestion extends Question
A MultipleChoiceQuestion includes list of possible answers.
-
Constructor Summary
Constructors Constructor Description MultipleChoiceQuestion(java.lang.String prompt, java.lang.String answer, java.lang.String[] choices)
Constructs a MultipleChoiceQuestion with the given prompt, answer, and choices. -
Method Summary
Modifier and Type Method Description boolean
checkAnswer(java.lang.String answer)
Checks if the user's answer matches this MultipleChoiceQuestion's expected answer.java.lang.String
getPrompt()
Returns the prompt for this MultipleChoiceQuestion followed by the list of choices.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
MultipleChoiceQuestion
public MultipleChoiceQuestion(java.lang.String prompt, java.lang.String answer, java.lang.String[] choices)Constructs a MultipleChoiceQuestion with the given prompt, answer, and choices.- Parameters:
prompt
- the question's promptanswer
- the question's answer; this value should be a letter whose position in the alphabet corresponds to the index of the correct answer inchoices
. For example, the answerB
corresponds tochoices[1]
choices
- the list of choices for this question; this array can be of any length
-
-
Method Details
-
checkAnswer
public boolean checkAnswer(java.lang.String answer)Checks if the user's answer matches this MultipleChoiceQuestion's expected answer. This method will consider either the letter of the choice to be correct OR the actual text of the response (both checks are case-insensitive).For example, if the correct answer is C and the choices are:
- Do
- Re
- Mi
Then both "C" and "Mi" (and any variation of upper/lower case for either) would be considered valid responses.
- Overrides:
checkAnswer
in classQuestion
- 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 MultipleChoiceQuestion followed by the list of choices.
-