Employee
package com.hp.demo11.demo06; public abstract class Employee { private String name; private int yf; public abstract double salary(int yf); public Employee() { } public Employee(String name, int yf) { this.name = name; this.yf = yf; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getYf() { return yf; } public void setYf(int yf) { this.yf = yf; } }
SalariedEmployee
package com.hp.demo11.demo06; public class SalariedEmployee extends Employee { private double yx;//月薪 public SalariedEmployee(double yx) { this.yx = yx; } public SalariedEmployee(String name, int yf, double yx) { super(name, yf); this.yx = yx; } public double getYx() { return yx; } public void setYx(double yx) { this.yx = yx; } @Override public double salary(int yf) { double salary = this.yx; if (super.getYf() == yf) { salary += 100; System.out.println(super.getName()+"因为过生日,奖励100"); } return salary; } }
HourlyEmployee
package com.hp.demo11.demo06; public class HourlyEmployee extends Employee{ private double xsg;//工作薪资 private int xss;//工作时长 public HourlyEmployee(double xsg,int xss){ this.xsg = xsg; this.xss = xss; } public HourlyEmployee(String name, int yf, double xsg, int xss) { super(name, yf); this.xsg = xsg; this.xss = xss; } public double getXsg() { return xsg; } public void setXsg(double xsg) { this.xsg = xsg; } public int getXss() { return xss; } public void setXss(int xss) { this.xss = xss; } @Override public double salary(int yf) { double salary =0 ; //工作时长超过160小时 if (xss > 160){ salary = 160 * this.xsg + (this.xss- 160)*1.5*this.xsg; } //是否过生日 if (super.getYf() == yf) { salary +=100; System.out.println(super.getName()+"因为过生日,奖励100"); } return salary; } }
SalesEmployee
package com.hp.demo11.demo06; public class SalesEmployee extends Employee { private double sales;//销售额 private double rate;//提成 public SalesEmployee(double sales, double rate) { this.sales = sales; this.rate = rate; } public SalesEmployee(String name, int yf, double sales, double rate) { super(name, yf); this.sales = sales; this.rate = rate; } public SalesEmployee() { } public double getSales() { return sales; } public void setSales(double sales) { this.sales = sales; } public double getRate() { return rate; } public void setRate(double rate) { this.rate = rate; } @Override public double salary(int yf) { double salary = this.sales * this.rate; if (super.getYf()== yf) { salary += 100; System.out.println(super.getName()+"因为过生日,奖励100"); } return salary; } }
BasePlusSalesEmployee
package com.hp.demo11.demo06; public class BasePlusSalesEmployee extends SalesEmployee{ private double dixin;//底薪 public double getDixin() { return dixin; } public void setDixin(double dixin) { this.dixin = dixin; } public BasePlusSalesEmployee(String name, int yf, double sales, double rate, double dixin) { super(name, yf, sales, rate); this.dixin = dixin; } public BasePlusSalesEmployee(double dixin) { this.dixin = dixin; } @Override public double salary(int yf) { double zong = dixin+super.getRate() * super.getSales(); if (super.getYf() == yf) { zong +=100; System.out.println(super.getName()+"因为过生日,奖励100"); } return zong; } }
Tex
package com.hp.demo11.demo06; public class Tex { public static void main(String[] args) { Employee[] employees = new Employee[10]; employees[0] = new SalariedEmployee("lll", 8, 1000); employees[1] = new HourlyEmployee("iii", 5, 80, 180); employees[2] = new SalesEmployee("ppp", 8, 80, 100); employees[3] = new BasePlusSalesEmployee("llll", 8, 80, 15, 1500); for (int i = 0; i <employees.length ; i++) { if (employees[i] != null) { double salary =employees[i].salary(8); System.out.println(employees[i].getName()+"工资为"+salary); } } } }