/* * @topic T11333 Spring 2017 Inheritance Demo * @brief class Company */ package inheritancedemo; import java.util.ArrayList; public class Company { //-------------------------------------- // data attributes //-------------------------------------- private ArrayList< Employee > employees = new ArrayList< Employee >(); private TimeTable timeTable = new TimeTable(); //-------------------------------------- // operations //-------------------------------------- public void populateTimetable() { for ( Employee emp : employees ) { if ( emp instanceof EmployeeFT ) { timeTable.addEntry( TimeSlotType.WEEKEND, emp.getEmployeeID(), 1/*day*/ ); timeTable.addEntry( TimeSlotType.WEEKDAY, emp.getEmployeeID(), 1/*day*/ ); } else { // for part-timer testing timeTable.addEntry( TimeSlotType.WEEKDAY, emp.getEmployeeID(), 8/*hours*/ ); } }//for }//populateTimetable double computePayroll() { double companyTotal = 0.0; ArrayList< TimeSlot > table = timeTable.getTimeTable(); // for each employee... for ( Employee emp : employees ) { // for each time they worked... double payPeriodPay = 0.0; for ( TimeSlot slot : table ) { // accumulate the employee's pay if ( slot.getEmployeeID() == emp.getEmployeeID() ) { // accumulate pay payPeriodPay += slot.getRate() * slot.getUnits() * emp.getRate(); } } // accumulate the company total companyTotal += payPeriodPay; System.out.println( "ID: " + emp.getEmployeeID() + " paid " + payPeriodPay ); } return companyTotal; }//computePayroll public void addEmployee( int employeeID, EmployeeType type, double pay ) { switch ( type ) { case FULL_TIME: employees.add( new EmployeeFT( employeeID, pay ) ); return; case PART_TIME: employees.add( new EmployeePT( employeeID, pay ) ); return; default: // TODO: throw an exception later... } }//addEmployee }//class Company