/**
 * Class for simulating large numbers of volleyball games and comparing
 * statistics on rally and sideout scoring.
 *   @author Dave Reed
 *   @version 10/25/05
 */
public class VolleyballStats
{
    public static final int INITIAL_REPS = 10000;
    public static final int INITIAL_POINTS = 25;
    private int numGames;  
    private int winPoints;
    
    /**
     * Constructs the simulator with defaults of INITIAL_REPS games to be
     *   played, each up to a winning score of INITIAL_POINTS
     */
    public VolleyballStats()
    {
        numGames = INITIAL_REPS;
        winPoints = INITIAL_POINTS;
    }

    /**
     * Accessor method for the number of games to be played.
     *   @return the number of games
     */
    public int getNumberOfGames()
    {
        return numGames;
    }
    
    /**
     * Mutator method to change the number of games to be played.
     *   @param newNum the new number of games
     */
    public void setNumberOfGames(int newNum)
    {
        numGames = newNum;
    }
    
    /**
     * Accessor method for the number of points required to win a game.
     *   @return the number of points
     */
    public int getPointsToWin()
    {
        return winPoints;
    }
    
    /**
     * Mutator method to change the number of points required to win a game.
     *   @param newNum the new number of points
     */
    public void setPointsToWin(int newNum)
    {
        winPoints = newNum;
    }
    
    /**
     * Simulates getNumberOfGames() volleyball games between teams with
     *   the speciefied power rankings, and displays statistics.
     *   @param rank1 the power ranking (0..100) of team 1
     *   @param rank2 the power ranking (0..100) of team 2
     */
    public void playGames(int rank1, int rank2)
    {
        VolleyballSim game = new VolleyballSim(rank1, rank2);
        
        int numWinsRally = 0;
        for (int i = 0; i < getNumberOfGames(); i++) {
            if (game.playGameRally(getPointsToWin()) == 1) {
                numWinsRally++;
            }
        }
        
        System.out.println("Assuming (" + rank1 + "-" + rank2 +
                           ") rankings over " + getNumberOfGames() + 
                           " games to " + getPointsToWin() + ":");
        System.out.println("  team 1 winning percentage:  " +
                           100.0*numWinsRally/getNumberOfGames() + "%"); 
        System.out.println();
    }
}
