/*                                      
 * Payroll.java 
 *
 * Version: 
 *     $Id: Payroll.java,v 1.2 2002/03/17 12:48:15 jmg Exp $ 
 * 
 * Revisions: 
 *     $Log: Payroll.java,v $
 *     Revision 1.2  2002/03/17 12:48:15  jmg
 *     made a subclass of Performer
 *
 *     Revision 1.1  2002/03/17 12:06:34  jmg
 *     Initial revision
 * 
 */

/**
 * Payroll class.  Manages list of actors that need to be paid
 *
 * @author Joe Geigel
 */
public class Payroll {

    /**
     * An array contain the managed performers
     */
    private Performer performer[];

    /**
     * The number of performers currently being managed
     */
    private int nPerf;

    /**
     * The maximum allowable performers that can be managed
     */
    private static final int MAXPERF = 100;

     /**
      *
      * Default constructor for the Payroll class
      *
      */
    public Payroll () {
	performer = new Performer[MAXPERF];
        nPerf = 0;
    }

    /**
     * Adds a performer to the payroll.  Will issue an error message 
     * if the payroll is currently full.
     *
     * @param P the performer to be added
     * @throws PayrollFullException if the payroll is indeed full.
     */
    public void addPerformer (Performer P) throws PayrollFullException
    {     
         if (nPerf == MAXPERF)
	     throw new PayrollFullException();
	 performer[nPerf] = P;
	 nPerf++;
     }

    /**
     *  Caculates the weekly pay for all of the performers
     *
     * @returns the total weekly pay
     */
    public double calculateTotalPay()
    {
	double sum = 0.0;
	for (int i=0; i < nPerf; i++)  sum += performer[i].calculatePay();
	return sum;
    }

    /**
     * A test program for the Payroll Class
     *
     * @param args Commandline arguments
     */
    static public void main (String args[])
    {
	// Create a payroll
	Payroll pay = new Payroll();

	// Create some performers, define the number of performances 
	// for each then add them to the payroll
	try {
	    Actor A = new Actor ("Nathan Lane");
	    A.perform (8);
	    pay.addPerformer (A);

	    A = new Actor ("Matthew Broderick");
	    A.perform (7);
	    pay.addPerformer (A);

	    A = new Actor ("Sean Connery");
	    A.perform (6);
	    pay.addPerformer (A);

	    A = new Actor ("Molly Ringwald");
	    A.perform (2);
	    pay.addPerformer (A);

	    Musician M = new Guitarist ("Jimi Hendrix");
	    M.perform (3);
	    pay.addPerformer(M);

	    M = new Guitarist ("Keith Richards");
	    M.perform (7);
	    pay.addPerformer(M);

	    M = new Drummer ("Ringo Starr");
	    M.perform (1);
	    pay.addPerformer(M);
	}
	catch (PayrollFullException E) {
	    System.err.println (E.getMessage());
	}


	// Calculate and print out the total weekly pay
	System.out.println ("The total weekly pay for this week is " + 
			    pay.calculateTotalPay());
    }
}
