某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,
属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
SalariedEmployee:Employee的子类,拿固定工资的员工。
属性:月薪
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
属性:底薪
写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
public class Employee {
private String name;
private int 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;
}
public Employee() {//创建一个无参构造
}
public Employee(String name,int month) {
this.name = name;
this.month = month;
}
//过生日多发一百块钱
public double getSalary(int month) {
if(this.month==month) {
return 100;
}else {
return 0;
}
}
SalariedEmployee:Employee的子类,拿固定工资的员工。
属性:月薪
public class SalariedEmployee extends Employee {
private double Salarys;
public SalariedEmployee() {
super();
}
public SalariedEmployee(String name,int month,double Salarys) {
super(name,month);
this.Salarys=Salarys;
}
//发工资
public double getSalary(int month) {
return this.Salarys + super.getSalary(month);
}
public double getSalarys() {
return Salarys;
}
public void setSalarys(double salarys) {
Salarys = salarys;
}
}
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
public class HourlyEmployee extends Employee{
private double hSalary;//时薪
private int hours;//小时
public void sethSalary(double hSalary) {
this.hSalary = hSalary;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public HourlyEmployee() {
super();
}
public HourlyEmployee(String name,int month,double hSalary,int hours) {
super(name,month);
this.hSalary=hSalary;
this.hours=hours;
}
public double getSalary(int month) {
if(hSalary>=160) {
return (hours-160)*1.5+(hSalary*160)+super.getSalary(month);
}else {
return hSalary*hours+super.getSalary(month);
}
}
}
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
public class SalesEmployee extends Employee{
private double sale;//销售额
private double rte;//提成率
public SalesEmployee() {
super();
}
public SalesEmployee(String name,int month,double sale,double rte) {
super(name,month);
this.sale = sale;
this.rte = rte;
}
public double getSale() {
return sale;
}
public void setSale(double sale) {
this.sale = sale;
}
public double getRte() {
return rte;
}
public void setRte(double rte) {
this.rte = rte;
}
public double getSalary(int month) {
return sale*rte+super.getSalary(month);
}
}
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
属性:底薪
public class BasePlusSalesEmployee extends SalesEmployee{
private double dSalar;//底薪
public BasePlusSalesEmployee() {
super();
}
public BasePlusSalesEmployee(String name,int month,double sale,double rte,double dSalar) {
super(name,month,sale,rte);
this.dSalar = dSalar;
}
public double getdSalar() {
return dSalar;
}
public void setdSalar(double dSalar) {
this.dSalar = dSalar;
}
public double getSalary(int month) {
return dSalar+super.getSalary(month);
}
}
public class Test {
public static void main(String[] args) {
SalariedEmployee s1 = new SalariedEmployee("张三",3,9000);
HourlyEmployee h1 = new HourlyEmployee("李四",6,20,220);
SalesEmployee sa1 = new SalesEmployee("王二",5,600000,0.05);
BasePlusSalesEmployee b1 = new BasePlusSalesEmployee("麻子",1,1000000,0.02,1500);
Employee[]emp = {s1,h1,sa1,b1};
System.out.println("输入查询的工资月份:");
Scanner sc = new Scanner(System.in);
int month=sc.nextInt();
System.out.println("姓名"+"\t"+"生日月份"+"\t"+"当前月份"+"当月工资"+"\t");
for (int i = 0; i < emp.length; i++) {
System.out.println(emp[i].getName()+"\t"+emp[i].getMonth()+"\t"+month+"\t"+emp[i].getSalary(month));
}
}
}