/*                                      
 * Payroll.java 
 *
 * Version: 
 *     $Id: Payroll.java,v 1.1 2002/03/17 12:06:34 jmg Exp $ 
 * 
 * Revisions: 
 *     $Log: Payroll.java,v $
 *     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 actors
     */
    private Actor actors[];

    /**
     * The number of actors currently being managed
     */
    private int nActors;

    /**
     * The maximum allowable actors that can be managed
     */
    private static final int MAXACTOR = 100;

     /**
      *
      * Default constructor for the Payroll class
      *
      */
    public Payroll () {
	actors = new Actor[MAXACTOR];
        nActors = 0;
    }

    /**
     * Adds an actor to the payroll.  Will issue an error message if the payroll
     * is currently full.
     *
     * @param A the actor to be added
     */
     public void addActor (Actor A)
     {
         if (nActors == MAXACTOR) {
             System.err.println ("Payroll is full.  Consider a show with less actors!");
         }
         else {
             actors[nActors] = A;
             nActors++;
         }
     }

     /**
      *  Caculates the weekly pay for all of the actors
      *
      * @returns the total weekly pay
      */
      public double calculateTotalPay()
      {
          double sum = 0.0;
          for (int i=0; i < nActors; i++)  sum += actors[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 actors, define the number of performances for each
          // then add them to the payroll
          Actor A = new Actor ("Nathan Lane");
          A.perform (8);
          pay.addActor (A);

          A = new Actor ("Matthew Broderick");
          A.perform (7);
          pay.addActor (A);

          A = new Actor ("Sean Connery");
          A.perform (6);
          pay.addActor (A);

          A = new Actor ("Molly Ringwald");
          A.perform (2);
          pay.addActor (A);

          // Calculate and print out the total weekly pay
          System.out.println ("The total weekly pay for this week is " + 
		pay.calculateTotalPay());
     }
}
