exe
Class mcQuestion

java.lang.Object
  extended by exe.question
      extended by exe.mcQuestion
Direct Known Subclasses:
XMLmcQuestion

public class mcQuestion
extends question

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.

Author:
? (original author), Ben Tidman (original comments), Andrew Jungwirth (editing and Javadoc comments)

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

choices

protected java.util.Vector<java.lang.String> choices
Holds the answer choices for this question.


correctChoice

protected int correctChoice
Keeps track of the correct answer's position in the 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.


correctChoiceStr

protected java.lang.String correctChoiceStr
Stores the String value of the correct answer.

Constructor Detail

mcQuestion

public 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.

Parameters:
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

insertQuestion

public void insertQuestion()
Description copied from class: question
Writes a reference to this question at the current position in the specified PrintWriter output stream using the GAIGS question reference format.

Specified by:
insertQuestion in class question

animalInsertQuestion

public void animalInsertQuestion()
Description copied from class: question
Writes a reference to this question at the current position in the specified PrintWriter output stream using the ANIMAL question reference format.

Specified by:
animalInsertQuestion in class question

addChoice

public void addChoice(java.lang.String choice)
Adds an answer choice to the 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.

Parameters:
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.

setAnswer

public void setAnswer(int choice)
Sets the 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.

Parameters:
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.

setAnswer

public 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.

Sets the 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.

Parameters:
choice - Defines the String for which this method searches to find the correct answer to this mcQuestion.

shuffle

public 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. 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.


writeQuestionInfo

public void writeQuestionInfo()
Description copied from class: question
Writes this question's information at the current position in the specified PrintWriter output stream using the GAIGS question format.

Specified by:
writeQuestionInfo in class question

animalWriteQuestionInfo

public void animalWriteQuestionInfo()
Description copied from class: question
Writes this question's information at the current position in the specified PrintWriter output stream using the ANIMAL question format.

Specified by:
animalWriteQuestionInfo in class question