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/BasicStrategy.java,v 1.3 2004/06/03 03:18:23 tj_willis Exp $
019     */ 
020    package net.sourceforge.pavlov.user;
021    
022    import java.util.*;
023    import org.apache.log4j.*;
024    
025    
026    /**
027     * A non-plug-in default strategy so that Pavlov can operate if the
028     * strategy directory is empty or damaged.  Returns the question with
029     * the fewest number of answers.
030     *
031     * @author <a href="mailto:tj_willis@users.sourceforge.net"> T.J. Willis </a>
032     * @version $Revision: 1.3 $
033     */
034    public class BasicStrategy
035        extends AbstractStrategy
036    {
037    
038        /**
039         * Creates a new <code>BasicStrategy</code> instance.
040         *
041         */
042        public BasicStrategy()
043        {
044            super();
045        }
046    
047        /**
048         * Creates a new <code>BasicStrategy</code> instance.
049         *
050         */
051        public BasicStrategy(Collection<QuestionData> questionList)
052        {
053            super(questionList);
054        }
055    
056        /**
057         * Returns a short descriptive name for this strategy.
058         * @return a <code>String</code> value
059         */
060        public String getName()
061        {
062            return "Answered Fewest Times";
063        }
064    
065        /**
066         * Returns a short descriptive name for this strategy.
067         * @return a <code>String</code> value
068         */
069        public String getDescription()
070        {
071            return "Chooses questions you've answered the fewest times";
072        }
073        
074        /**
075         * Returns the next question using the abovementioned strategy.
076         *
077         * @return a <code>QuestionData</code> value
078         */
079        public QuestionData getQuestion(Vector<QuestionData> exclusion) {
080    
081            QuestionData q = null;
082    
083            int lowest = Integer.MAX_VALUE;
084    
085            for(QuestionData x: questions) {
086                // if question is in exclusion vector, don't consider it
087                if(exclusion!=null && exclusion.contains( x)){
088                    continue;
089                }
090                final int tot = x.getTotal();
091                if (tot < lowest) {
092                    lowest = tot;
093                    if(lowest==0) return x;
094                    q = x;
095                }
096            }
097            return q;
098        }
099        
100    }