2、某公司的雇员分为以下若干类:
Employee:
这是所有员工总的父类,
属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
SalariedEmployee:
Employee的子类,拿固定工资的员工。
属性:月薪
BasePlusSalesEmployee:
public class BasePlusSalesEmployee extends SalesEmployee {
private int dixin;
public BasePlusSalesEmployee(int yuexiaoshou, double ticheng, int dixin) {
super(yuexiaoshou, ticheng);
this.dixin = dixin;
}
public BasePlusSalesEmployee(String name, int month, int yuexiaoshou, double ticheng, int dixin) {
super(name, month, yuexiaoshou, ticheng);
this.dixin = dixin;
}
public int getDixin() {
return dixin;
}
public void setDixin(int dixin) {
this.dixin = dixin;
}
public int getSalary(int month) {
if (month == getMonth()) {
double b = getDixin() + (getYuexiaoshou() * getTicheng());
return (int) (b + 100);
} else {
double b = getDixin() + (getYuexiaoshou() * getTicheng());
return (int) b;
}
}
}
Employee:
public class Employee {
private String name;
private int month;
public Employee() {
}
public Employee(String name, int month) {
this.name = name;
this.month = month;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
}
HourlyEmployee:
public class HourlyEmployee extends Employee {
private int meiXiaoShiGongZi;
private int meiYueGongZuoXiaoShiSshu;
public HourlyEmployee(int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {
this.meiXiaoShiGongZi = meiXiaoShiGongZi;
this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
}
public HourlyEmployee(String name, int month, int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {
super(name, month);
this.meiXiaoShiGongZi = meiXiaoShiGongZi;
this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
}
public int getMeiXiaoShiGongZi() {
return meiXiaoShiGongZi;
}
public void setMeiXiaoShiGongZi(int meiXiaoShiGongZi) {
this.meiXiaoShiGongZi = meiXiaoShiGongZi;
}
public int getMeiYueGongZuoXiaoShiSshu() {
return meiYueGongZuoXiaoShiSshu;
}
public void setMeiYueGongZuoXiaoShiSshu(int meiYueGongZuoXiaoShiSshu) {
this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;
}
public int getSalary(int month) {
if (getMeiYueGongZuoXiaoShiSshu() > 160) {
if (month == getMonth()) {
double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());
int i = getMeiXiaoShiGongZi() * 160;
return (int) (v + i + 100);
} else {
double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());
int i = getMeiXiaoShiGongZi() * 160;
return (int) (v + i);
}
} else {
if (month == getMonth()) {
int i = (getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu()) + 100;
return i;
} else {
int i = getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu();
return i;
}
}
}
}
SalariedEmployee:
public class SalariedEmployee extends Employee{
private int yuexin;
public SalariedEmployee(int yuexin){
this.yuexin= yuexin;
}
public SalariedEmployee(String name, int month, int yueXin) {
super(name, month);
this.yuexin = yueXin;
}
public int getYuexin() {
return yuexin;
}
public void setYuexin(int yuexin) {
this.yuexin = yuexin;
}
public int getSalary(int month) {
if (month == getMonth()) {
return getYuexin()+100;
}
return getYuexin();
}
}
SalesEmployee:
public class SalesEmployee extends Employee{
private int yuexiaoshou;
private double ticheng;
public SalesEmployee(int yuexiaoshou, double ticheng) {
this.yuexiaoshou = yuexiaoshou;
this.ticheng = ticheng;
}
public SalesEmployee(String name, int month, int yuexiaoshou, double ticheng) {
super(name, month);
this.yuexiaoshou = yuexiaoshou;
this.ticheng = ticheng;
}
public int getYuexiaoshou() {
return yuexiaoshou;
}
public void setYuexiaoshou(int yuexiaoshou) {
this.yuexiaoshou = yuexiaoshou;
}
public double getTicheng() {
return ticheng;
}
public void setTicheng(double ticheng) {
this.ticheng = ticheng;
}
public int getSalary(int month){
if (month == getMonth()) {
double a = (getYuexiaoshou() * getTicheng());
int a1 = (int) a + 100;
return a1;
}else {
double a = (getYuexiaoshou() * getTicheng());
return (int) a;
}
}
}
Test:
public class Test {
public static void main(String[] args) {
Employee salariedEmployee = new SalariedEmployee("小红",10,5000);
Employee hourlyEmployee = new HourlyEmployee("小花",10,10,180);
Employee salesEmployee = new SalesEmployee("小明",6,2000,2);
Employee basePlusSalesEmployee = new BasePlusSalesEmployee("小美",5,1000,2,3000);
int salary = ((SalariedEmployee) salariedEmployee).getSalary(10);
System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);
int salary1 = ((HourlyEmployee) hourlyEmployee).getSalary(10);
System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);
int salary2 = ((SalesEmployee) salesEmployee).getSalary(6);
System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);
int salary3 = ((BasePlusSalesEmployee) basePlusSalesEmployee).getSalary(5);
System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);
}
}