某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,
属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
SalariedEmployee:Employee的子类,拿固定工资的员工。
属性:月薪
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
属性:底薪写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
注意:要求把每个类都做成完全封装,不允许非私有化属性。
package work07_17_03;
/**
*
* @author Administrator
* @desc 员工总类
*/
public class Employee {
private String name;
private int month;
public Employee(String name,int month) {
this.month = month;
this.name = name;
}
public double getSalary(int month) {
if (this.month == month) {
return 100;
} else {
return 0;
}
}
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;
}
}
package work07_17_03;
/**
*
* @author Administrator
* @desc Employee的子类,
* 拿固定工资的员工
*/
public class SalariedEmployee extends Employee{
private double fixedSalary;//固定工资
public SalariedEmployee(String name, int month, double fixedSalary) {
super(name, month);
this.fixedSalary = fixedSalary;
}
@Override
public double getSalary(int month) {
// TODO Auto-generated method stub
return super.getSalary(month) + fixedSalary;
}
public double getFixedSalary() {
return fixedSalary;
}
public void setFixedSalary(double fixedSalary) {
this.fixedSalary = fixedSalary;
}
}
package work07_17_03;
/**
*
* @author Administrator
* @desc Employee的子类,
* 按小时拿工资的员工,
* 每月工作超出160小时的部分按照1.5倍工资发放
*/
public class HourlyEmployee extends Employee{
private int workHour;//工作的小时数
private double hourlySalary;//每小时的工资
public HourlyEmployee(String name, int month, int workHour, double hourlySalary) {
super(name, month);
this.hourlySalary = hourlySalary;
this.workHour = workHour;
}
@Override
public double getSalary(int month) {
if (workHour < 160) {
return super.getSalary(month) + workHour * hourlySalary;
} else {
return super.getSalary(month) + 160 * hourlySalary + (workHour - 160) * hourlySalary * 1.5;
}
}
public int getWorkHour() {
return workHour;
}
public void setWorkHour(int workHour) {
this.workHour = workHour;
}
public double getHourlySalary() {
return hourlySalary;
}
public void setHourlySalary(double hourlySalary) {
this.hourlySalary = hourlySalary;
}
}
package work07_17_03;
/**
*
* @author Administrator
* @desc Employee的子类,
* 销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
*/
public class SalesEmployee extends Employee{
private double monthlySalesVolume;//月销售额
private double royaltyRate;//提成率
public SalesEmployee(String name, int month, double monthlySalesVolume, double royaltyRate) {
super(name, month);
this.monthlySalesVolume = monthlySalesVolume;
this.royaltyRate = royaltyRate;
}
@Override
public double getSalary(int month) {
return super.getSalary(month) + monthlySalesVolume * royaltyRate;
}
public double getMonthlySalesVolume() {
return monthlySalesVolume;
}
public void setMonthlySalesVolume(double monthlySalesVolume) {
this.monthlySalesVolume = monthlySalesVolume;
}
public double getRoyaltyRate() {
return royaltyRate;
}
public void setRoyaltyRate(double royaltyRate) {
this.royaltyRate = royaltyRate;
}
}
package work07_17_03;
/**
*
* @author Administrator
* @desc SalesEmployee的子类,
* 有固定底薪的销售人员,工资由底薪加上销售提成部分
*/
public class BasePlusSalesEmployee extends SalesEmployee{
private double basicSalary;//底薪
public BasePlusSalesEmployee(String name, int month, double monthlySalesVolume, double royaltyRate, double basicSalary) {
super(name, month, monthlySalesVolume, royaltyRate);
this.basicSalary = basicSalary;
}
@Override
public double getSalary(int month) {
// TODO Auto-generated method stub
return super.getSalary(month) + basicSalary;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
}
package work07_17_03;
/**
*
* @author Administrator
* @desc 测试类
*/
public class Test {
public static void main(String[] args) {
Employee[] employees = {
new SalariedEmployee("张三", 6 , 3500),
new HourlyEmployee("李四", 8, 280, 12),
new SalesEmployee("王五", 7, 50000, 0.05),
new BasePlusSalesEmployee("赵六", 10, 50000, 0.05, 2000)
};
for (Employee i : employees) {
System.out.println(i.getName() + "的工资为" + i.getSalary(6));
}
}
}