📄 testemployee.java
字号:
public class TestEmployee {
public static void main(String[] args) {
}
}
class Employee{
private String name;
private int birthMonth;
public Employee(String name,int birthMonth){
this.name=name;
this.birthMonth=birthMonth;
}
public String getName(){
return name;
}
public double getSalary(int month){
if (this.birthMonth==month) return 100;
else return 0;
}
}
class SalariedEmployee extends Employee{
private double salary;
public SalariedEmployee(String name,int birthMonth,double salary){
//把name,birthMonth两个参数传给父类,设置父类属性
super(name,birthMonth);
this.salary=salary;
}
public double getSalary(int month){
return salary+super.getSalary(month);
}
}
class HourlyEmployee extends Employee{
private double salaryPerHour;
private int hours;
public HourlyEmployee(String name, int birthMonth, double salaryPerHour, int hours) {
super(name, birthMonth);
this.salaryPerHour = salaryPerHour;
this.hours = hours;
}
public double getSalary(int month){
double result=0;
if (hours>160) result=160*this.salaryPerHour+(hours-160)*this.salaryPerHour*1.5;
else result=this.hours*this.salaryPerHour;
return result+super.getSalary(month);
}
}
class SalesEmployee extends Employee{
private double sales;
private double rate;
public SalesEmployee(String name, int birthMonth, double sales, double rate) {
super(name, birthMonth);
this.sales = sales;
this.rate = rate;
}
public double getSalary(int month) {
return this.sales*this.rate+super.getSalary(month);
}
}
class BasePlusSalesEmployee extends SalesEmployee{
private double basedSalary;
public BasePlusSalesEmployee(String name, int birthMonth, double sales, double rate, double basedSalary) {
super(name, birthMonth, sales, rate);
this.basedSalary = basedSalary;
}
public double getSalary(int month) {
return this.basedSalary+super.getSalary(month);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -