|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectexe.question
exe.mcQuestion
public class mcQuestion
This class extends question to provide support for
mulitple-choice questions.
In order to use mcQuestion or any of question's
other derived classes in a script-producing program, the script-producing
program must import the package exe.
An mcQuestion is added to a showfile by placing a question
reference at the end of the snapshot in which the question is to appear and
then by appending the question information to the question section at the
end of the file.
Question reference for an mcQuestion:
MCQUESTION id
Question information for an mcQuestion:
MCQUESTION id
The question text appears here.
ENDTEXT
The correct answer choice appears here.
ENDCHOICE
Incorrect answer choice 1 appears here.
ENDCHOICE
Incorrect answer choice 2 appears here.
ENDCHOICE
. . .
Incorrect answer choice n appears here.
ENDCHOICE
ANSWER
1
ENDANSWER
Note that if the correct answer is added first, the correct answer is 1; if
the correct answer is added second, the correct answer is 2; ...; if the
correct answer is added as item n, the correct answer is n.
After all the answers have been added and the correct answer has been set,
the answer choices can be shuffled using the shuffle() method.
| Field Summary | |
|---|---|
protected java.util.Vector<java.lang.String> |
choices
Holds the answer choices for this question. |
protected int |
correctChoice
Keeps track of the correct answer's position in the Vector
of choices. |
protected java.lang.String |
correctChoiceStr
Stores the String value of the correct answer. |
| Fields inherited from class exe.question |
|---|
id, mustBeAsked, out, questionText |
| Constructor Summary | |
|---|---|
mcQuestion(java.io.PrintWriter out,
java.lang.String id)
Constructs a new mcQuestion object that is distinguished
by id and outputs its information to out. |
|
| Method Summary | |
|---|---|
void |
addChoice(java.lang.String choice)
Adds an answer choice to the Vector that stores the answer
choices for this mcQuestion. |
void |
animalInsertQuestion()
Writes a reference to this question at the current position
in the specified PrintWriter output stream using the ANIMAL
question reference format. |
void |
animalWriteQuestionInfo()
Writes this question's information at the current position
in the specified PrintWriter output stream using the ANIMAL
question format. |
void |
insertQuestion()
Writes a reference to this question at the current position
in the specified PrintWriter output stream using the GAIGS
question reference format. |
void |
setAnswer(int choice)
Sets the correctChoice variable that is used to track the
position of the correct answer to this mcQuestion. |
void |
setAnswer(java.lang.String choice)
Deprecated. Replaced by setAnswer(int). Since this method may
fail to properly change the value of
correctChoice, this method should not be used
in new code. |
void |
shuffle()
Randomly exchanges the positions of the answer choices contained within choices so that the answer choices appear in a different
order than they were added. |
void |
writeQuestionInfo()
Writes this question's information at the current position
in the specified PrintWriter output stream using the GAIGS
question format. |
| Methods inherited from class exe.question |
|---|
getID, setMustBeAsked, setQuestionText |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Vector<java.lang.String> choices
protected int correctChoice
Vector
of choices.
Note that the value stored is one greater than the index of the answer
in the Vector. For instance, if the correct answer is the
first answer stored in choices, the value of
correctChoice is 1, not 0.
protected java.lang.String correctChoiceStr
String value of the correct answer.
| Constructor Detail |
|---|
public mcQuestion(java.io.PrintWriter out,
java.lang.String id)
mcQuestion object that is distinguished
by id and outputs its information to out.
out - Specifies the output stream to which this
mcQuestion should perform its write operations.id - Gives this mcQuestion a String that
can be used to uniquely identify it from other
question objects in a collection.| Method Detail |
|---|
public void insertQuestion()
questionquestion at the current position
in the specified PrintWriter output stream using the GAIGS
question reference format.
insertQuestion in class questionpublic void animalInsertQuestion()
questionquestion at the current position
in the specified PrintWriter output stream using the ANIMAL
question reference format.
animalInsertQuestion in class questionpublic void addChoice(java.lang.String choice)
Vector that stores the answer
choices for this mcQuestion.
The value passed to choice is added to the end of the
Vector of answer choices.
choice - Specifies the text of the answer choice that is to be
added to the Vector of choices. This is the
answer choice that appears in the question window when
this mcQuestion is asked.public void setAnswer(int choice)
correctChoice variable that is used to track the
position of the correct answer to this mcQuestion.
The value passed to choice is set as the
correctChoice.
Note that the value passed to choice must be one greater
than the correct answer choice's index in the
choices Vector. For example, the first answer added via
addChoice(String) is 1.
choice - Indicates the correct answer to this
mcQuestion. The value must be one greater
than the answer's index in the Vector of
choices, as described above.public void setAnswer(java.lang.String choice)
setAnswer(int). Since this method may
fail to properly change the value of
correctChoice, this method should not be used
in new code.
correctChoice variable that is used to track the
position of the correct answer to this mcQuestion by
finding the answer choice that matches the value passed to
choice.
This method performs a linear search through the Vector of
choices in order to find the specified choice. If the value passed to
choice does not exactly match any of the answer choices,
correctChoice is not changed. As such, this method should
not be used in new code and only remains to support legacy code.
choice - Defines the String for which this method
searches to find the correct answer to this
mcQuestion.public void shuffle()
choices so that the answer choices appear in a different
order than they were added.
Whenever the correct answer choice is swapped with another choice, the
value of correctChoice is changed so its value still
accurately tracks the correct answer to this mcQuestion.
public void writeQuestionInfo()
questionquestion's information at the current position
in the specified PrintWriter output stream using the GAIGS
question format.
writeQuestionInfo in class questionpublic void animalWriteQuestionInfo()
questionquestion's information at the current position
in the specified PrintWriter output stream using the ANIMAL
question format.
animalWriteQuestionInfo in class question
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||