【发布时间】:2021-11-29 23:50:51
【问题描述】:
我有一个抽象类 Staff 有一个属性系数(工资)。我有两个类 Employee 有自己的属性是 overTimes,Manager 有一个属性是从 Staff 扩展的 title 并实现接口 ICalculate 有一个函数 calculateSalary()。从员工和经理创建的所有对象,我添加到 ArrayList listOfStaffs。那么在我计算工资后,我该如何安排员工随着工资上升呢?谢谢 这是我的员工课
public abstract class Staff {
private double staffCoefficient;
public Staff(double staffCoefficient) {
super();
this.staffCoefficient = staffCoefficient;
}
public double getStaffCoefficient() {
return staffCoefficient;
}
public void setStaffCoefficient(double staffCoefficient) {
this.staffCoefficient = staffCoefficient;
}
}
这是我的 Employee 类
public class Employee extends Staff implements ICaculator {
private int overTimes;
public Employee(double staffCoefficient) {
super(staffCoefficient);
// TODO Auto-generated constructor stub
}
public Employee(double staffCoefficient, int overTimes) {
super(staffCoefficient);
this.overTimes = overTimes;
}
public int getOverTimes() {
return overTimes;
}
public void setOverTimes(int overTimes) {
this.overTimes = overTimes;
}
@Override
public BigDecimal calculateSalary() {
double salary = super.getStaffCoefficient() * 3000000 + getOverTimes() * 200000;
BigDecimal bigSalary = new BigDecimal(salary);
return bigSalary;
}
}
这是我的经理类
public class Manager extends Staff implements ICaculator {
private String title;
public Manager(double staffCoefficient) {
super(staffCoefficient);
}
public Manager(double staffCoefficient, String title) {
super(staffCoefficient);
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public BigDecimal calculateSalary() {
Double salary = super.getStaffCoefficient() * 5000000;
if (getTitle().contentEquals("Business Leader")) {
salary += 8000000;
BigDecimal bigSalary = new BigDecimal(salary);
return bigSalary;
} else if (getTitle().contentEquals("Project Leader")) {
salary += 5000000;
BigDecimal bigSalary = new BigDecimal(salary);
return bigSalary;
} else if (getTitle().contentEquals("Technical Leader")) {
salary += 6000000;
BigDecimal bigSalary = new BigDecimal(salary);
return bigSalary;
} else {
BigDecimal bigSalary = new BigDecimal(salary);
return bigSalary;
}
}
}
我可以显示所有员工的工资,但我不知道如何安排他们。请帮我。非常感谢。
【问题讨论】:
标签: java oop inheritance arraylist