net.sourceforge.pavlov.library
Class Question

java.lang.Object
  extended by net.sourceforge.pavlov.library.Question
All Implemented Interfaces:
Serializable, Comparable

public class Question
extends Object
implements Serializable, Comparable

The text of a question, its correct answer, incorrect answers, and associated information.

See Also:
Serialized Form

Constructor Summary
Question()
          Creates a new Question instance.
Question(String _id)
          Creates a new Question instance.
 
Method Summary
 void addHint(String x)
          Adds a hint for the question.
 void addWrongAnswer(String x)
          Adds an incorrect answer for the question.
 int compareTo(Object obj)
           
 Question deepCopy()
          Uses a nifty trick from "Design Patterns in Java" to create a completely independent copy of this question.
 boolean equals(Object obj)
          Returns true if the given object is a Question and its fields are equal to mine.
protected  void finalize()
           
 Vector<String> getAnswersShuffled()
          Gets the vector of incorrect answers.
 String getHint()
          Returns a random hint.
 String getID()
          Returns this question's ID.
 String getImageFile()
          Gets the name of the image file to be shown for this question.
 URL getImageURL()
          Gets the URL of the image file to be shown for this question.
 String getRightAnswer()
          Returns this question's correct answer.
 String getRightAnswerEncoded()
          Returns this question's correct answer URLEncoded.
 String getSoundFile()
          Returns the name of the sound file to play when this question is presented to the user.
 String getText()
          Returns this question's text.
 String getWrongAnswer()
          Returns a random incorrect answer.
 String getWrongAnswer(int i)
          Returns the numbered incorrect answer, or null if it doesn't exist.
 Vector<String> getWrongAnswers()
          Gets the vector of incorrect answers.
 boolean hasImage()
          Returns true if there is an image to display for this question.
static Question makeBlankQuestion()
          Creates a blank question suitable for editing.
 void setHints(Vector<String> v)
          Sets the hints for this question.
 void setId(String x)
          Sets the question's ID.
 void setImageFile(String x)
          Sets the image to be displayed for this question.
 void setRightAnswer(String x)
          Set's the question's correct answer.
 void setSoundFile(String x)
          Sets the sound to play for this question.
 void setText(String x)
          Sets the text of the question.
 void setWrongAnswer(String ans, int i)
          Sets wrongAnswer number i to ans.
 void setWrongAnswers(Vector<String> v)
          Sets all the incorrect answers for this question.
 String toHTML(Writer writer, Random v)
          Dumps this queston as HTML to the given writer.
 void toXML(Writer writer)
          Dumps this question as an XML entity to the given writer.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Question

public Question()
Creates a new Question instance.


Question

public Question(String _id)
Creates a new Question instance.

Parameters:
_id - a String value
Method Detail

compareTo

public int compareTo(Object obj)
Specified by:
compareTo in interface Comparable

setId

public void setId(String x)
Sets the question's ID.

Parameters:
x - a String value

setText

public void setText(String x)
Sets the text of the question.

Parameters:
x - a String value

setRightAnswer

public void setRightAnswer(String x)
Set's the question's correct answer.

Parameters:
x - a String value

addWrongAnswer

public void addWrongAnswer(String x)
Adds an incorrect answer for the question.

Parameters:
x - a String value

addHint

public void addHint(String x)
Adds a hint for the question.

Parameters:
x - a String value

setSoundFile

public void setSoundFile(String x)
Sets the sound to play for this question.

Parameters:
x - a String value

setImageFile

public void setImageFile(String x)
Sets the image to be displayed for this question.

Parameters:
x - a String value

getImageFile

public String getImageFile()
Gets the name of the image file to be shown for this question.

Returns:
a String value

getImageURL

public URL getImageURL()
Gets the URL of the image file to be shown for this question.

Returns:
a String value

hasImage

public boolean hasImage()
Returns true if there is an image to display for this question.

Returns:
a boolean value

setHints

public void setHints(Vector<String> v)
Sets the hints for this question.

Parameters:
v - a Vector value

setWrongAnswers

public void setWrongAnswers(Vector<String> v)
Sets all the incorrect answers for this question.

Parameters:
v - a Vector value

setWrongAnswer

public void setWrongAnswer(String ans,
                           int i)
Sets wrongAnswer number i to ans.

Parameters:
ans - a String value
i - an int value

getWrongAnswers

public Vector<String> getWrongAnswers()
Gets the vector of incorrect answers.

Returns:
a Vector value

getAnswersShuffled

public Vector<String> getAnswersShuffled()
Gets the vector of incorrect answers.

Returns:
a Vector value

getID

public String getID()
Returns this question's ID.

Returns:
a String value

getText

public String getText()
Returns this question's text.

Returns:
a String value

getRightAnswer

public String getRightAnswer()
Returns this question's correct answer.

Returns:
a String value

getRightAnswerEncoded

public String getRightAnswerEncoded()
Returns this question's correct answer URLEncoded.

Returns:
a String value

getWrongAnswer

public String getWrongAnswer()
Returns a random incorrect answer.

Returns:
a String value

getWrongAnswer

public String getWrongAnswer(int i)
Returns the numbered incorrect answer, or null if it doesn't exist.

Parameters:
i - an int value
Returns:
a String value

getHint

public String getHint()
Returns a random hint.

Returns:
a String value

getSoundFile

public String getSoundFile()
Returns the name of the sound file to play when this question is presented to the user.

Returns:
a String value

toXML

public void toXML(Writer writer)
           throws IOException
Dumps this question as an XML entity to the given writer.

Parameters:
writer - a java.io.Writer value
Throws:
IOException - if an error occurs

toHTML

public String toHTML(Writer writer,
                     Random v)
              throws IOException
Dumps this queston as HTML to the given writer.

Parameters:
writer - a java.io.Writer value
v - a Random value
Returns:
a String value
Throws:
IOException - if an error occurs

makeBlankQuestion

public static Question makeBlankQuestion()
Creates a blank question suitable for editing.

Returns:
a Question value

equals

public boolean equals(Object obj)
Returns true if the given object is a Question and its fields are equal to mine.

Overrides:
equals in class Object
Parameters:
obj - an Object value
Returns:
a boolean value

deepCopy

public Question deepCopy()
Uses a nifty trick from "Design Patterns in Java" to create a completely independent copy of this question. Resulting question can be edited without changing this question's values.

Returns:
a Question value

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable