net.sourceforge.pavlov.main
Class Quiz

java.lang.Object
  extended by net.sourceforge.pavlov.main.Quiz
All Implemented Interfaces:
AnswerEventProducer, AnswerListener, StrategyListener

public class Quiz
extends Object
implements StrategyListener, AnswerListener, AnswerEventProducer

Contains state information for a quiz in progress.


Field Summary
protected  Vector<AnswerListener> answerListeners
          Components, mostly pluglets, that respond to users answers.
protected  ChapterReference chapRef
          The chapter to choose questions from.
 
Constructor Summary
Quiz(AbstractPavlovApplication absPav, User aUser, ChapterReference ref)
          Creates a new Quiz instance.
 
Method Summary
 void addAnswerListener(AnswerListener g)
          Register an AnswerListener with this quiz.
 void addQuestionChangedListener(QuestionChangedListener lis)
          Adds an object to be notified when the question has changed.
 void answerEvent(AnswerEvent e)
          The user has answered a question.
 ChapterData getChapterData()
          Return the current ChapterData.
 ChapterReference getChapterReference()
          Describe getChapterReference method here.
protected  Question getNextQuestion()
          Gets a valud question using the user's current question selection strategy.
 User getUser()
          Returns the active user.
 String getUserName()
          Describe getUserName method here.
 Question newQuestion()
          Ask the user a new question.
protected  void notifyAnswerListeners(boolean correct)
          Let the registered answerlisteners know that the user has answered a question.
protected  void notifyQuestionChangedListeners()
          Let registerd answer listeners know that the question has changed.
protected  void rightAnswer()
          Tell quizData and chapterData that the user answered a question correctly.
 void save()
          Saves the user's statistical data.
 void setStrategy(AbstractStrategy s)
          Choose the question selection strategy.
 void strategyChanged(AbstractStrategy which)
          Implements the StrategyListener interface.
protected  void wrongAnswer()
          Tell quizData and chapterData that the user answered a question incorrectly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chapRef

protected ChapterReference chapRef
The chapter to choose questions from.


answerListeners

protected Vector<AnswerListener> answerListeners
Components, mostly pluglets, that respond to users answers.

Constructor Detail

Quiz

public Quiz(AbstractPavlovApplication absPav,
            User aUser,
            ChapterReference ref)
Creates a new Quiz instance. The AbstractPavlovApplication may safely be null.

Parameters:
absPav - an AbstractPavlovApplication value
aUser - an User value
ref - a ChapterReference value
Method Detail

getChapterReference

public ChapterReference getChapterReference()
Describe getChapterReference method here.

Returns:
a ChapterReference value

getUserName

public String getUserName()
Describe getUserName method here.

Returns:
a String value

getUser

public User getUser()
Returns the active user.

Returns:
a String value

addQuestionChangedListener

public void addQuestionChangedListener(QuestionChangedListener lis)
Adds an object to be notified when the question has changed.

Parameters:
lis - a QuestionChangedListener value

newQuestion

public Question newQuestion()
Ask the user a new question.

Returns:
a Question value

notifyQuestionChangedListeners

protected void notifyQuestionChangedListeners()
Let registerd answer listeners know that the question has changed.


save

public void save()
          throws FileNotFoundException,
                 IOException
Saves the user's statistical data.

Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

rightAnswer

protected void rightAnswer()
Tell quizData and chapterData that the user answered a question correctly.


wrongAnswer

protected void wrongAnswer()
Tell quizData and chapterData that the user answered a question incorrectly. Delegate to abstractPavlov to inform the user.


notifyAnswerListeners

protected void notifyAnswerListeners(boolean correct)
Let the registered answerlisteners know that the user has answered a question.

Parameters:
correct - a boolean value

getChapterData

public ChapterData getChapterData()
Return the current ChapterData.

Returns:
a ChapterData value

getNextQuestion

protected Question getNextQuestion()
Gets a valud question using the user's current question selection strategy.

Returns:
a Question value

answerEvent

public void answerEvent(AnswerEvent e)
The user has answered a question. Handle it.

Specified by:
answerEvent in interface AnswerListener
Parameters:
e - an AnswerEvent value

setStrategy

public void setStrategy(AbstractStrategy s)
Choose the question selection strategy.

Parameters:
s - an AbstractStrategy value

strategyChanged

public void strategyChanged(AbstractStrategy which)
Implements the StrategyListener interface.

Specified by:
strategyChanged in interface StrategyListener
Parameters:
which - an AbstractStrategy value

addAnswerListener

public void addAnswerListener(AnswerListener g)
Register an AnswerListener with this quiz.

Specified by:
addAnswerListener in interface AnswerEventProducer
Parameters:
g - an AnswerListener value