001 /* PAVLOV -- Multiple Choice Study System
002 * Copyright (C) 2000 - 2004 T.J. Willis
003 *
004 * This program is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU General Public License
006 * as published by the Free Software Foundation; either version 2
007 * of the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, write to the Free Software
016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017 *
018 * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/event/AnswerEvent.java,v 1.8 2004/07/01 09:03:42 tj_willis Exp $
019 */
020 package net.sourceforge.pavlov.event;
021 import net.sourceforge.pavlov.user.*;
022
023 /**
024 * An event generated when a user answers a question in a quiz. Contains,
025 * directly and indirectly, almost all available information about the user,
026 * the current book and chapter, and the current quiz.
027 *
028 * @author <a href="mailto:"></a>
029 * @version $Revision: 1.8 $
030 */
031 public final class AnswerEvent {
032 /**
033 * Whether the answer was correct.
034 *
035 */
036 private boolean correct;
037 /**
038 * The user who answered the question.
039 *
040 */
041 private User user;
042 /**
043 * Information about the current quiz.
044 *
045 */
046 private QuizData quiz;
047 /**
048 * Data about the question that was answered.
049 *
050 */
051 private QuestionData question;
052 /**
053 * Data about the chapter containing the question that was answered.
054 *
055 */
056 private ChapterData chapter;
057 /**
058 * Data about the book containing the question that was answered.
059 *
060 */
061 private BookData book;
062 /**
063 * Whether this was the first answer in a quiz.
064 *
065 */
066 private boolean newQuiz;
067
068 /**
069 * Creates a new <code>AnswerEvent</code> instance.
070 *
071 * @param wasCorrect whether the answer was correct
072 */
073 public AnswerEvent(boolean wasCorrect)
074 {
075 correct = wasCorrect;
076 }
077
078 /**
079 * Creates a new <code>AnswerEvent</code> instance.
080 *
081 * @param wasCorrect whether the answer was correct
082 * @param theUser an <code>User</code> value
083 * @param theQues a <code>QuestionData</code> value
084 * @param theQuiz a <code>QuizData</code> value
085 * @param theBook a <code>BookData</code> value
086 * @param theChapter a <code>ChapterData</code> value
087 * @param newQuiz a <code>boolean</code> value
088 */
089 public AnswerEvent(final boolean correct, final User user, final QuestionData question,
090 final QuizData quiz, final BookData book, final ChapterData chapter,
091 final boolean newQuiz)
092 {
093 this.correct = correct;
094 this.user = user;
095 this.question = question;
096 this.quiz = quiz;
097 this.book = book;
098 this.chapter = chapter;
099 this.newQuiz = newQuiz;
100 }
101
102 /**
103 * Whether the answer was correct.
104 *
105 * @return a <code>boolean</code> value
106 */
107 public boolean isCorrect()
108 {
109 return correct;
110 }
111
112 public void setCorrect(boolean newCorrect){
113 correct = newCorrect;
114 }
115
116 /**
117 * How many questions answered in the current quiz.
118 *
119 * @return an <code>int</code> value
120 */
121 public int getNumberOfAnswers()
122 {
123 return quiz.getTotal();
124 }
125
126 /**
127 * How many correct answers in the current quiz.
128 *
129 * @return an <code>int</code> value
130 */
131 public int getNumberOfCorrectAnswers()
132 {
133 return quiz.getRight();
134 }
135 /**
136 * How many incorrect answers in the current quiz.
137 *
138 * @return an <code>int</code> value
139 */
140 public int getNumberOfIncorrectAnswers()
141 {
142 return quiz.getWrong();
143 }
144 /**
145 * Percentage of correct answers in the current quiz.
146 *
147 * @return a <code>double</code> value
148 */
149 public double getPercentageOfCorrectAnswers()
150 {
151 return quiz.getPercentage();
152 }
153
154 /**
155 * Returns the QuizData for the current quiz.
156 *
157 * @return a <code>QuizData</code> value
158 */
159 public QuizData getQuizData()
160 {
161 return quiz;
162 }
163
164 /**
165 * Returns the ChapterStatistics for the chapter containing the
166 * answered question.
167 *
168 * @return a <code>ChapterStatistics</code> value
169 */
170 public ChapterStatistics getChapterStatistics()
171 {
172 return chapter.getChapterStatistics();
173 }
174
175 /**
176 * Returns the QuestionData for the answered question.
177 *
178 * @return a <code>QuestionData</code> value
179 */
180 public QuestionData getQuestionData()
181 {
182 return question;
183 }
184
185 /**
186 * Returns the User who answered the question.
187 *
188 * @return an <code>User</code> value
189 */
190 public User getUser()
191 {
192 return user;
193 }
194
195 /**
196 * Returns the ChapterData for the chapter containing the answered
197 * question.
198 *
199 * @return a <code>ChapterData</code> value
200 */
201 public ChapterData getChapterData()
202 {
203 return chapter;
204 }
205
206
207
208 /**
209 * Returns the BookData for the Book containing the answered question.
210 *
211 * @return a <code>BookData</code> value
212 */
213 public BookData getBookData()
214 {
215 return book;
216 }
217 /**
218 * Returns true if this is the first answer in a quiz.
219 *
220 * @return a <code>boolean</code> value
221 */
222 public boolean isNewQuiz()
223 {
224 return newQuiz;
225 }
226 }
227
228
229
230
231
232
233
234
235