题目:
某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:void getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励1000元。
SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。
Employee类:
public abstract class Employee {
public String name;
public int birthday;
public abstract void getSalary(int month);
}
SalariedEmployee类:
public class SalariedEmployee extends Employee {
public double yx;//月薪
@Override
public void getSalary(int month) {
if(birthday == month){
System.out.println(name+month+"月份的工资为"+(yx+1000)+"元");
}else{
System.out.println(name+month+"月份的工资为"+yx+"元");
}
}
}
HourlyEmployee类:
public class HourlyEmployee extends Employee {
public double hourMoney;//每小时的工资
public double hour;//每月工作的小时数
@Override
public void getSalary(int month) {
double money;
if(hour > 160){
money = hourMoney*160+(hour-160)*hourMoney*1.5;
}else{
money = hourMoney*hour;
}
if(birthday == month){
System.out.println(name+month+"月份的工资为"+(money+1000)+"元");
}else{
System.out.println(name+month+"月份的工资为"+money+"元");
}
}
}
SalesEmploye类:
public class SalesEmployee extends Employee {
public double salarM;//月销售额
public double tcl;//提成率
@Override
public void getSalary(int month) {
if(birthday == month){
System.out.println(name+month+"月份的工资为"+(salarM*tcl+1000)+"元");
}else{
System.out.println(name+month+"月份的工资为"+salarM*tcl+"元");
}
}
}
BasePlusSalesEmployee类:
public class BasePlusSalesEmployee extends SalesEmployee {
public double dx;//底薪
@Override
public void getSalary(int month) {
if(birthday == month){
System.out.println(name+month+"月份的工资为"+(salarM*tcl+dx+1000)+"元");
}else{
System.out.println(name+month+"月份的工资为"+(salarM*tcl+dx)+"元");
}
}
}
Test类:
public class Test {
public static void main(String[] args) {
SalariedEmployee s = new SalariedEmployee();
s.name = "张三";
s.birthday = 1;
s.yx = 3000;
s.getSalary(2);
HourlyEmployee h = new HourlyEmployee();
h.name = "李四";
h.birthday = 2;
h.hourMoney = 10;
h.hour = 161;
h.getSalary(2);
SalesEmployee s1 = new SalesEmployee();
s1.name = "王晓";
s1.birthday = 3;
s1.salarM = 20000;
s1.tcl = 0.1;
s1.getSalary(2);
BasePlusSalesEmployee b = new BasePlusSalesEmployee();
b.name = "杨毅";
b.birthday = 4;
b.salarM = 20000;
b.tcl = 0.1;
b.dx = 2000;
b.getSalary(2);
}
}