某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,
属性:
员工的姓名,员工的生日月份。
方法:getSalary(intmonth)
根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。
SalariedEmployee:
Employee 的子类,拿固定工资的员工。
属性:月薪
HourlyEmployee:
Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。
属性:每小时的工资、每月工作的小时数
SalesEmployee:
Employee 的子类,销售人员,工资由月销售额和提成率决定。
属性:月销售额、提成率
BasePlusSalesEmployee:
SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。
属性:底薪。
根据要求创建 SalariedEmployee 、 HourlyEmployees 、SaleEmployee 和 BasePlusSalesEmployee四个类的对象各一个,
并计算某个月这四个对象的工资。
注意:要求把每个类都做成完全封装,不允许非私有化属性。
public class Employee extends Test{ //Employee类private String name;private int BirthMonth;private double salary;public double getSalary() {return salary;}public void setSalary(double salary) {this.salary = salary;}public Employee() {}public Employee(String name, int birthMonth) {this.name = name;BirthMonth = birthMonth;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getBirthMonth() {return BirthMonth;}public void setBirthMonth(int birthMonth) {BirthMonth = birthMonth;}public void getSalary(int month){if(getBirthMonth() == month){System.out.println("生日快乐,工资加100");setSalary(getSalary() + 100);}}
}
public class SalariedEmployee extends Employee{ //SalariedEmployee 类 private double salary;public SalariedEmployee() {}public SalariedEmployee(String name, int birthMonth, double salary) {super(name, birthMonth);this.salary = salary;}@Overridepublic double getSalary() {return salary;}@Overridepublic void setSalary(double salary) {this.salary = salary;}
}
public class HourlyEmployee extends Employee{ //HourlyEmployee 类private int workHour;private int hourSalary;public HourlyEmployee() {}public HourlyEmployee(String name, int birthMonth, int workHour, int hourSalary) {super(name, birthMonth);this.workHour = workHour;this.hourSalary = hourSalary;}public HourlyEmployee(int workHour, int hourSalary) {this.workHour = workHour;this.hourSalary = hourSalary;}public HourlyEmployee(String name, int birthMonth) {super(name, birthMonth);}public int getWorkHour() {return workHour;}public void setWorkHour(int workHour) {this.workHour = workHour;}public int getHourMoney() {return hourSalary;}public void setHourMoney(int hourMoney) {hourSalary = hourMoney;}public void setMoney(){if(getWorkHour() > 160){double extra = (getWorkHour() - 160) * 1.5 * getHourMoney();double salary = 160 * getHourMoney();setSalary(salary + extra);}else{double salary = getWorkHour() * getHourMoney();setSalary(salary);System.out.println("工资:" + getSalary());}}
}
public class SalesEmployee extends Employee{ //SalesEmployee 类private double monthlySales;private double commission;public SalesEmployee() {}public SalesEmployee(String name, int birthMonth, double monthlySales, double commission) {super(name, birthMonth);hlySales = monthlySales;thismission = commission;}public SalesEmployee(double monthlySales, double commission) {hlySales = monthlySales;thismission = commission;}public double getMonthlySales() {return monthlySales;}public void setMonthlySales(double monthlySales) {hlySales = monthlySales;}public double getCommission() {return commission;}public void setCommission(double commission) {thismission = commission;}public void setMoney(){setSalary(getMonthlySales() * getCommission());}
}
public class BasePlusSalesEmployee extends SalesEmployee{ //BasePlusSalesEmployee 类private double Base;public BasePlusSalesEmployee() {}public BasePlusSalesEmployee(String name, int birthMonth, double monthlySales, double commission, double base) {super(name, birthMonth, monthlySales, commission);Base = base;}public BasePlusSalesEmployee(double base) {Base = base;}public double getBase() {return Base;}public void setBase(double base) {Base = base;}public void setMoney(){setSalary((getMonthlySales() * getCommission()) + Base);}
}
public class Test { //Test 类public static void main(String[] args) {int month = 10;Employee a = new HourlyEmployee("test1",10,160,15);HourlyEmployee b = (HourlyEmployee) a;b.setMoney();b.getSalary(month);System.out.println("姓名:" + b.getName() + "生日" + b.getBirthMonth() + "工作时长" + b.getWorkHour() + "时薪" + b.getHourMoney() + "此月工资" + b.getSalary());Employee c = new SalariedEmployee("test2",10,4000);SalariedEmployee d = (SalariedEmployee) Salary(month);System.out.println("姓名:" + d.getName() + "生日" + d.getBirthMonth() + "此月工资" + d.getSalary() );Employee e = new SalesEmployee("test3",8,100000,0.005);SalesEmployee f = (SalesEmployee) Salary(month);f.setMoney();System.out.println("姓名:" + f.getName() + "生日" + f.getBirthMonth() + "销售额" + f.getMonthlySales() + "提成率" + f.getCommission() * 100 + "%" + "此月工资" + f.getSalary() );Employee g = new BasePlusSalesEmployee("test4",10,100000,0.005,4000);BasePlusSalesEmployee h = (BasePlusSalesEmployee) Salary(month);h.setMoney();System.out.println("姓名:" + h.getName() + "生日" + BirthMonth() + "固定工资" + h.getBase()+ "销售额" + h.getMonthlySales() + "提成率" + h.getCommission() * 100 + "%" + "此月工资" + h.getSalary() );}
}
2021年11月6日01:39:16
本文发布于:2024-02-04 06:31:39,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170701113853146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |