//实现人力资源部对全职员工的访问 public override void visit(FulltimeEmployee employee) { int workTime = employee.getWorkTime(); Console.WriteLine("正式员工" + employee.getName() + "实际工作时间为:" + workTime + "小时。"); if (workTime > 40) { Console.WriteLine("正式员工" + employee.getName() + "加班时间为:" + (workTime - 40) + "小时。"); } else if (workTime < 40) { Console.WriteLine("正式员工" + employee.getName() + "请假时间为:" + (40 - workTime) + "小时。"); } }
//实现财务部对全职员工的访问 public override void visit(FulltimeEmployee employee) { int workTime = employee.getWorkTime(); double weekWage = employee.getWeeklyWage(); if (workTime > 40) { weekWage = weekWage + (workTime - 40) * 100; } else if (workTime < 40) { weekWage = weekWage - (40 - workTime) * 80; if (weekWage < 0) { weekWage = 0; } } Console.WriteLine("正式员工" + employee.getName() + "实际工资为:" + weekWage + "元。"); }
public void Test() { EmployeeList list = new EmployeeList(); Employee fte1, fte2, fte3, pte1, pte2; fte1 = new FulltimeEmployee("张无忌", 3200.00, 45); fte2 = new FulltimeEmployee("杨过", 2000.00, 40); fte3 = new FulltimeEmployee("段誉", 2400.00, 38); pte1 = new ParttimeEmployee("洪七公", 80.00, 20); pte2 = new ParttimeEmployee("郭靖", 60.00, 18); list.addEmployee(fte1); list.addEmployee(fte2); list.addEmployee(fte3); list.addEmployee(pte1); list.addEmployee(pte2); Department dep = new FADepartment(); list.accept(dep); }
//声明一组重载的访问方法,用于访问不同类型的具体元素 public abstract void visit(FulltimeEmployee employee);