package cn.hp.demo01;
public class Hepo {
public static void main(String[] args) {
Employee e1 = new SalariedEmployee("张三", 6, 9000);
e1.getSalary(6);
Employee e2 = new HourlyEmployee("李四", 7, 60, 200);
e2.getSalary(6);
Employee e3 = new HourlyEmployee("王五", 2, 60, 150);
e3.getSalary(6);
Employee e4 = new SalesEmployee("赵六", 11, 70000.0, 0.15);
e4.getSalary(6);
Employee e5 = new BasePlusSalesEmployee("孙子", 4, 10000, 0.10, 8000.0);
e5.getSalary(6);
}
}
package cn.hp.demo01;
/*
*这是所有员工总的父类,
* */
public abstract class Employee {
private String name;//员工姓名
private int birthdayMonth;//生日月份
public Employee() {
}
public Employee(String name, int birthdayMonth) {
this.name = name;
this.birthdayMonth = birthdayMonth;
}
public abstract void getSalary(int month);
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBirthdayMonth() {
return birthdayMonth;
}
public void setBirthdayMonth(int birthdayMonth) {
this.birthdayMonth = birthdayMonth;
}
}
package cn.hp.demo01;
/*
Employee的子类
* 按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放
* */
public class HourlyEmployee extends Employee{
private int workingHours;//工作时间
private double hourlySalary;//每小时的工资
public HourlyEmployee(int workingHours) {
this.workingHours = workingHours;
}
public HourlyEmployee(String name, int birthdayMonth, int workingHours) {
super(name, birthdayMonth);
this.workingHours = workingHours;
}
public HourlyEmployee(String 李四, int i, int i1, int i2) {
}
public int getWorkingHours() {
return workingHours;
}
public void setWorkingHours(int workingHours) {
this.workingHours = workingHours;
}
public double getHourlySalary() {
return hourlySalary;
}
public void setHourlySalary(double hourlySalary) {
this.hourlySalary = hourlySalary;
}
@Override
public void getSalary(int month) {
double salary1 = 0;
double salary2 = 0;
if (workingHours<=160) {
salary1 = hourlySalary * workingHours;
System.out.println(this.getName()+"本月工资为:"+salary1);
}else {
salary2 = ((hourlySalary-160)*1.5+160)*hourlySalary;
}
System.out.println(this.getName()+"本月工资为:"+salary2);
}
}
package cn.hp.demo01;
/*
* Employee的子类,拿固定工资的员工
* */
public class SalariedEmployee extends Employee{
private double monthSalary;//月薪
public SalariedEmployee(double monthSalary) {
this.monthSalary = monthSalary;
}
public SalariedEmployee(String name, int birthdayMonth, double monthSalary) {
super(name, birthdayMonth);
this.monthSalary = monthSalary;
}
public double getMonthSalary() {
return monthSalary;
}
public void setMonthSalary(double monthSalary) {
this.monthSalary = monthSalary;
}
@Override
public void getSalary(int month) {
if (month == getBirthdayMonth()) {
System.out.println(this.getName()+"本月的工资为:"+(monthSalary+100));
}else {
System.out.println(this.getName()+"本月的工资为:"+monthSalary);
}
}
}
package cn.hp.demo01;
/*
* Employee的子类,销售人员,工资由月销售额和提成率决定
* */
public class SalesEmployee extends Employee{
private double saleroom;//月销售额
private double royaltyRate;//提成率
public SalesEmployee(double saleroom) {
this.saleroom = saleroom;
}
public SalesEmployee(String name, int birthdayMonth, double saleroom) {
super(name, birthdayMonth);
this.saleroom = saleroom;
}
public SalesEmployee(String name, int birthdayMonth, double saleroom, double rate) {
}
public SalesEmployee() {
}
public double getSaleroom() {
return saleroom;
}
public void setSaleroom(double saleroom) {
this.saleroom = saleroom;
}
public double getRoyaltyRate() {
return royaltyRate;
}
public void setRoyaltyRate(double royaltyRate) {
this.royaltyRate = royaltyRate;
}
@Override
public void getSalary(int month) {
System.out.println(this.getName()+"本月工资为:"+(month == getBirthdayMonth() ? (saleroom * royaltyRate + 100) : saleroom * royaltyRate));
}
}
package cn.hp.demo01;
public class BasePlusSalesEmployee extends SalesEmployee{
private double basicSalary;
public BasePlusSalesEmployee() {
super();
}
public BasePlusSalesEmployee(String name, int birthdayMonth, double saleroom, double rate, double basicSalary) {
super(name, birthdayMonth, saleroom, rate);
this.basicSalary = basicSalary;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
@Override
public void getSalary(int month) {
double salary = getSaleroom() * getRoyaltyRate() + basicSalary;
System.out.println("本月工资为:" +(month == getBirthdayMonth() ? (salary + 100) : salary));
}
}