某公司的雇员分为以下若干类:
Employee:
这是所有员工总的父类,
属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100
public abstract class Employee {
private String name;//员工的姓名
private int March;//员工的生日月份
public double getSalary(int month){
if(this.March==month){
return 100;
}
return 0;
}
public Employee() {
}
public Employee(String name, int march) {
this.name = name;
this.March = march;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getB() {
return March;
}
public void setB(int march) {
this.March = march;
}
}
SalariedEmployee:
Employee的子类,拿固定工资的员工。
属性:月薪
public class SalariedEmployee extends Employee {
/* Employee的子类,拿固定工资的员工。
属性:月薪
* */
private double monthlypay;//月薪
public SalariedEmployee(String name, int march, double salesVolume, double royaltyRate) {
}
@Override
public double getSalary(int month) {
return monthlypay + super.getSalary(month);
}
public SalariedEmployee(String name, int month, double monthlypay) {
super(name, month);
this.monthlypay = monthlypay;
}
public SalariedEmployee() {
}
}
HourlyEmployee:
Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
public class HourlyEmployee extends Employee{
/*Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
* */
private int salary;//每小时的工资
private int hour;//每月工作的小时数
@Override
public double getSalary(int month) {
if (hour > 160) {
return salary * 160 + (hour - 160) * 1.5 * salary + super.getSalary(month);
}
return salary*hour+super.getSalary(month);
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public HourlyEmployee(String name, int month, int salary, int hour) {
super(name, month);
this.salary = salary;
this.hour = hour;
}
public HourlyEmployee() {
}
}
SalesEmployee:
Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
public class SalesEmployee extends Employee {
/*
* Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
* */
private double salesVolume;//月销售额
private double royaltyRate;//提成率
@Override
public double getSalary(int month) {
return salesVolume * royaltyRate + super.getSalary(month);
}
public double getSalesVolume() {
return salesVolume;
}
public void setSalesVolume(double salesVolume) {
this.salesVolume = salesVolume;
}
public double getRoyaltyRate() {
return royaltyRate;
}
public void setRoyaltyRate(double royaltyRate) {
this.royaltyRate = royaltyRate;
}
public SalesEmployee(String name, int month, double salesVolume, double royaltyRate) {
super(name, month);
this.salesVolume = salesVolume;
this.royaltyRate = royaltyRate;
}
public SalesEmployee() {
}
}
BasePlusSalesEmployee:
SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
属性:底薪。
public class BasePlusSalesEmployee extends SalariedEmployee {
/*SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
属性:底薪。
* */
private double basicSalary;//底薪
public double getSalary(int month){
return basicSalary+super.getSalary(month);
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
public BasePlusSalesEmployee(String name, int b, double salesVolume, double royaltyRate, double basicSalary) {
super(name, b, salesVolume, royaltyRate);
this.basicSalary = basicSalary;
}
public BasePlusSalesEmployee(String name, int b, double salesVolume, double royaltyRate) {
super(name, b, salesVolume, royaltyRate);
}
}
把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
public class Test {
public static void main(String[] args) {
SalariedEmployee se = new SalariedEmployee("张张",10,7000);
System.out.println("张张工资"+se.getSalary(1));
System.out.println("张张生日"+se.getSalary(10));
HourlyEmployee he = new HourlyEmployee("",11,40,200);
System.out.println("lisa工资"+he.getSalary(1));
System.out.println("lisa生日"+he.getSalary(11));
SalesEmployee s = new SalesEmployee("",9,30000,0.7);
System.out.println("阿孔工资"+s.getSalary(2));
System.out.println("阿孔生日"+s.getSalary(9));
}
}