(1) Employee :这是所有员工总的父类。
属性:员工的姓名,员工的生日月份
方法: getSalary(int month)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元.
(2)SalariedEmployee : Employee 的子类,拿固定工资的员工。
属性∶月薪。
(3)HourlyEmployee : Employee 的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性︰每小时的工资、每月工作的小时数。
(4) SalesEmployee : Employee 的子类,销售,工资由月销售额和提成率决定。
属性:月销售额、提成率.
(5)BasePlusSalesEmployee : SalesEmployee 的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。。
属性:底薪.
要求:
(1)创建SalariedEmployee、HourlyEmployee、SaleEmployee、BasePlusSalesEmployee四个类的对象各一个
(2)并调用父类getSalary(int money)方法计算某个月这四个对象各自的工资
注意:要求把每个类都做成完全封装,不允许非私有化属性。
编程∶在上一题的基础上,创建一个Employee 数组,分别创建若干不同的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;
}
public double getSalary(int month) {
if (month == this.month) {
return 100;
}
return 0;
}
}
class SalariedEmployee extends Employee {
private double salary;
public SalariedEmployee() {
}
public SalariedEmployee(double salary) {
this.salary = salary;
}
public SalariedEmployee(String name, int month, double salary) {
super(name, month);
this.salary = salary;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public double getSalary(int month) {
return super.getSalary(month) + salary;
}
}
class HourlyEmployee extends Employee {
private double hourlySalary;
private int hours;
public HourlyEmployee() {
}
public HourlyEmployee(double hourlySalary, int hours) {
this.hourlySalary = hourlySalary;
this.hours = hours;
}
public HourlyEmployee(String name, int month, double hourlySalary, int hours) {
super(name, month);
this.hourlySalary = hourlySalary;
this.hours = hours;
}
public double getHourlySalary() {
return hourlySalary;
}
public void setHourlySalary(double hourlySalary) {
this.hourlySalary = hourlySalary;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
@Override
public double getSalary(int month) {
if (hours <= 160) {
return super.getSalary(month) + hourlySalary * hours;
} else {
return super.getSalary(month) + (hours - 160) * 1.5 * hourlySalary + 160 * hourlySalary;
}
}
}
class SalesEmployee extends Employee {
private double sales;//月销额
private double rate;//提出率
public SalesEmployee() {
}
public SalesEmployee(double sales, double rate) {
this.sales = sales;
this.rate = rate;
}
public SalesEmployee(String name, int month, double sales, double rate) {
super(name, month);
this.sales = sales;
this.rate = rate;
}
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 getSalary(int month) {
return super.getSalary(month) + sales + rate;
}
}
class BasePlusSalesEmployee extends SalesEmployee {
private double baseSalesEmployee;
public BasePlusSalesEmployee() {
}
public BasePlusSalesEmployee(double baseSalesEmployee) {
this.baseSalesEmployee = baseSalesEmployee;
}
public BasePlusSalesEmployee(double sales, double rate, double baseSalesEmployee) {
super(sales, rate);
this.baseSalesEmployee = baseSalesEmployee;
}
public BasePlusSalesEmployee(String name, int month, double sales, double rate, double baseSalesEmployee) {
super(name, month, sales, rate);
this.baseSalesEmployee = baseSalesEmployee;
}
public double getBaseSalesEmployee() {
return baseSalesEmployee;
}
public void setBaseSalesEmployee(double baseSalesEmployee) {
this.baseSalesEmployee = baseSalesEmployee;
}
@Override
public double getSalary(int month) {
return super.getSalary(month)+baseSalesEmployee;
}
}
class TestEmployee{
public static void main(String[] args) {
SalariedEmployee salariedEmployee = new SalariedEmployee("张三",1,4000);
System.out.println(salariedEmployee.getSalary(2));
HourlyEmployee hourlyEmployee = new HourlyEmployee("李四",3,40,165);
System.out.println(hourlyEmployee.getSalary(3));
SalesEmployee salesEmployee = new SalesEmployee("王五",6,3000,4000);
System.out.println(salesEmployee.getSalary(9));
BasePlusSalesEmployee basePlusSalesEmployee = new BasePlusSalesEmployee("杰克",9,3500,1000,2000);
System.out.println(basePlusSalesEmployee.getSalary(5));
System.out.println("打印个员工五月的工资:");
Employee[] employee = new Employee[]{salariedEmployee,hourlyEmployee,salesEmployee,basePlusSalesEmployee};
for (int i=0;i<employee.length;i++){
System.out.println(employee[i].getSalary(5));
}
}
}