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/user/QuizCollection.java,v 1.6 2004/05/19 03:12:14 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.user; 021 import java.util.*; 022 import org.apache.log4j.*; 023 024 025 /** 026 * Data describing all the quizzes the user has taken on a given chapter. 027 * 028 * @author <a href="mailto:tj_willis@users.sourceforge.net"> T.J. Willis </a> 029 * @version $Revision: 1.6 $ 030 */ 031 public class QuizCollection { 032 /** 033 * List of quizzes. 034 * 035 */ 036 protected Vector<QuizData> quizzes; 037 038 /** 039 * Creates a new <code>QuizCollection</code> instance. 040 * 041 */ 042 public QuizCollection() { 043 quizzes = new Vector<QuizData>(); 044 045 } 046 047 /** 048 * Describe <code>getQuizzes</code> method here. 049 * 050 * @return a <code>Vector</code> value 051 */ 052 public Vector getQuizzes() 053 { 054 return quizzes; 055 } 056 057 /** 058 * Add a QuizData to the list. 059 * 060 * @param q a <code>QuizData</code> value 061 */ 062 public void addQuiz(QuizData q) { 063 quizzes.add(q); 064 } 065 066 /** 067 * Number of quizzes in this collection. 068 * 069 * @return an <code>int</code> value 070 */ 071 public int getNumberOfQuizzes() { 072 return quizzes.size(); 073 } 074 075 /** 076 * Returns descriptive statistics about these quizzes. 077 * 078 * @return a <code>QuizCollectionData</code> value 079 */ 080 public QuizCollectionData getStatistics() { 081 082 QuizCollectionData qcd = new QuizCollectionData(); 083 qcd.numQuizzes = quizzes.size(); 084 085 for(QuizData qq : quizzes) { 086 qcd.totalAsked += qq.getTotal(); 087 qcd.totalRight += qq.getRight(); 088 qcd.totalWrong += qq.getWrong(); 089 } 090 qcd.avgQuestionsPerQuiz = (1.0 * qcd.totalAsked) / (1.0 * qcd.numQuizzes); 091 return qcd; 092 } 093 094 /** 095 * Dumps these quizzes as XML to the given writer. 096 * 097 * @param writer a <code>java.io.Writer</code> value 098 * @exception java.io.IOException if an error occurs 099 */ 100 public void toXML(java.io.Writer writer) 101 throws java.io.IOException { 102 103 for(QuizData qq : quizzes) { 104 qq.toXML(writer); 105 } 106 } 107 108 /** 109 * Returns a vector of EasyGraphDataItems representing quiz percentages 110 * in this collection. 111 * 112 * @return a <code>Vector</code> value 113 */ 114 public Vector getPercentages() { 115 Vector<Double> v = new Vector<Double>(); 116 for(QuizData qq : quizzes) { 117 v.add(qq.getPercentage()); // java 1.5 autoboxing 118 } 119 return v; 120 } 121 122 }