1700472431
这就多了一个getTotalSalary方法。我们再来看实现类,如代码清单25-18所示。
1700472432
1700472433
代码清单25-18 具体访问者
1700472434
1700472435
public class Visitor implements IVisitor{
1700472436
1700472437
//部门经理的工资系数是5
1700472438
1700472439
private final static int MANAGER_COEFFICIENT=5;
1700472440
1700472441
//员工的工资系数是2
1700472442
1700472443
private final static int COMMONEMPLOYEE_COEFFICIENT=2;
1700472444
1700472445
//普通员工的工资总和
1700472446
1700472447
private int commonTotalSalary=0;
1700472448
1700472449
//部门经理的工资总和
1700472450
1700472451
private int managerTotalSalary=0;
1700472452
1700472453
//计算部门经理的工资总和
1700472454
1700472455
private void calManagerSalary(int salary){
1700472456
1700472457
this.managerTotalSalary=this.managerTotalSalary+salary
1700472458
1700472459
*MANAGER_COEFFICIENT;
1700472460
1700472461
}
1700472462
1700472463
//计算普通员工的工资总和
1700472464
1700472465
private void calCommonSlary(int salary){
1700472466
1700472467
this.commonTotalSalary=this.commonTotalSalary+
1700472468
1700472469
salary*COMMONEMPLOYEE_COEFFICIENT;
1700472470
1700472471
}
1700472472
1700472473
//获得所有员工的工资总和
1700472474
1700472475
public int getTotalSalary(){
1700472476
1700472477
return this.commonTotalSalary+this.managerTotalSalary;
1700472478
1700472479
}
1700472480
[
上一页 ]
[ :1.700472431e+09 ]
[
下一页 ]