/* CMIS141 Projec t 4: SalesTeam.java Author: Cameron Bunch Date: August 14, 2009 The SalesTeam class is used to create SalesTeam objects. The SalesTeam is the group of salespeople who form the team along with their personal information and historical sales information. */ public class SalesTeam { //--- Instance varaibles private String teamName; private Person[] member; private double[][] sales; // First index is person, second index is year private int baseYear; private int yearCount; //---------------------------------------------------------------------------- // // public SalesTeam( String teamName, int teamSize, int initBaseYear, int yearCount ) // // Constructor. // // Creates the member[] and sales[] arrays of sizes detrermined by the parameters. // Sets baseYear. If any parameter is invalid the member reference is set to null // to flag an invalid object. The minimum valid initial base year is 2005. The // yearCount includes the base year so it has a minimum value of 1. // public SalesTeam( String teamName, int teamSize, int initBaseYear, int yearCount ) { if( teamSize < 1 || initBaseYear < 2005 || yearCount < 1 ) { member = null; return; } this.teamName = teamName; member = new Person[teamSize]; baseYear = initBaseYear; sales = new double[teamSize][yearCount]; this.yearCount = yearCount; } //---------------------------------------------------------------------------- // // public Person getTeamMember( int index ) // // Returns the Person object for the team member at 'index' in the member[] array. // If 'index' is not valid returns null; // public Person getTeamMember( int index ) { if( member == null || index < 0 || index >= member.length ) return null; else return member[index]; } //---------------------------------------------------------------------------- // // public double getSales( int personIndex, int year ) // // Return the sales for the sales person at 'personIndex' during the year 'year'. // If either 'personIndex' or 'year' is invalid or the object is invalid return 0.0. // public double getSales( int personIndex, int year ) { int yearIndex; if( !isValid() ) return 0.0; yearIndex = year - baseYear; // Validate the person index if( getTeamMember(personIndex ) == null ) return 0.0; // Validate the year. if( yearIndex < 0 || yearIndex > sales[personIndex].length ) return 0.0; return sales[personIndex][yearIndex]; } //---------------------------------------------------------------------------- // // public double getBonus( int personIndex, int year ) // // Returns a calculated bonus for the preson selected by 'personIndex' for the // year specified by 'year'. If either the personIndex or year are not valid or // entire object is not valid then zero is returned. Otherwise 5% of the sales // for that person in the specified year is returned. // public double getBonus( int personIndex, int year ) { return getSales( personIndex, year ) * 0.05; } //---------------------------------------------------------------------------- // // public int getTeamSize() // // Returns the number of team members if the object is valid or 0 if not. // public int getTeamSize() { if( member != null ) return member.length; else return 0; } //---------------------------------------------------------------------------- // // public int getBaseYear() // // Returns the base year. // public int getBaseYear() { return baseYear; } //---------------------------------------------------------------------------- // // public int getYearCount() // // Returns the year count. // public int getYearCount() { return yearCount; } //---------------------------------------------------------------------------- // // public boolean isValid() // // Returns true if the object is valid else false. // public boolean isValid() { return member != null; } //---------------------------------------------------------------------------- // // public String getTeamName() // // Returns the team name string. // public String getTeamName() { return teamName; } // // // Setters // //---------------------------------------------------------------------------- // // public void setTeamMember( int personIndex, Person newMember ) // // Sets the sales person at 'personIndex' in the member[] array to the Person // referenced by 'member'. If the object is not valid (member is null), or the // 'personIndex' is not a vaild index for member[] no action is taken and no // error is reported. // public void setTeamMember( int personIndex, Person newMember ) { if( member == null || personIndex < 0 || personIndex > member.length ) return; member[personIndex] = newMember; } //---------------------------------------------------------------------------- // // public void setSales( int personIndex, int year, double salesAmount ) // // Sets the sales amount for the person person at 'personIndex' in the member[] // array for the year 'year' to salesAmount. If the object is not valid, the // personIndex is not valid, or the year is not valid no action is taken and // no error is reported. // public void setSales( int personIndex, int year, double salesAmount ) { if( getTeamMember( personIndex ) == null || year < baseYear || year-baseYear > sales[personIndex].length ) return; sales[personIndex][year-baseYear] = salesAmount; } //---------------------------------------------------------------------------- // // public void setTeamName( String teamName ) // // Sets the team name to the value of the 'teamName' parameter. // public void setTeamName( String teamName ) { this.teamName = teamName; } }