200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 某公司的雇员分为以下若干类: Employee:这是所有员工总的父类

某公司的雇员分为以下若干类: Employee:这是所有员工总的父类

时间:2022-09-28 18:40:27

相关推荐

某公司的雇员分为以下若干类:         Employee:这是所有员工总的父类

代码

/*某公司的雇员分为以下若干类:Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(intmonth)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。SalariedEmployee:Employee 的子类,拿固定工资的员工。属性:月薪HourlyEmployee:Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。属性:每小时的工资、每月工作的小时数SalesEmployee:Employee 的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率BasePlusSalesEmployee:SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。属性:底薪。根据要求创建 SalariedEmployee 、 HourlyEmployees 、SaleEmployee 和 BasePlusSalesEmployee四个类的对象各一个,并计算某个月这四个对象的工资。注意:要求把每个类都做成完全封装,不允许非私有化属性。*/public class Homework1 {public static void main(String[] args) {//创建对象Employee e1 = new SalariedEmployee("张三", 1, 2500);Employee e2 = new HourlyEmployee("李四", 2, 100, 200);Employee e3 = new SalesEmployee("赵六", 3, 1000000, 0.01);Employee e4 = new BasePlusSalesEmployee("钱七",4,100000, 0.02, 500);//获得薪水System.out.println(e1.getName() + "的工资是:" + e1.getSalary(4));System.out.println(e2.getName() + "的工资是:" + e2.getSalary(4));System.out.println(e3.getName() + "的工资是:" + e3.getSalary(4));System.out.println(e4.getName() + "的工资是:" + e4.getSalary(4));}}/*Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(intmonth)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。*/abstract class Employee{private String name;private int month;//constructorpublic Employee() {}public Employee(String name, int month) {this.name = name;this.month = month;}//setter and getterpublic 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 abstract double getSalary(int month);}/*SalariedEmployee:Employee 的子类,拿固定工资的员工。属性:月薪*/class SalariedEmployee extends Employee{//月薪private int monthlySalary;@Overridepublic double getSalary(int month) {if (this.getMonth() == month){return this.getMonthlySalary() + 100;}else{return this.getMonthlySalary();}}//constructorpublic SalariedEmployee() {}public SalariedEmployee(String name, int month, int monthlySalary) {super(name, month);this.monthlySalary = monthlySalary;}//setter and getterpublic int getMonthlySalary() {return monthlySalary;}public void setMonthlySalary(int monthlySalary) {this.monthlySalary = monthlySalary;}}/*HourlyEmployee:Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。属性:每小时的工资、每月工作的小时数*/class HourlyEmployee extends Employee{//小时工资int hourlyPayment;//每月工作小时数int workHour;@Overridepublic double getSalary(int month) {if (this.getWorkHour() > 160){if (this.getMonth() == month){return getHourlyPayment()*160 + getHourlyPayment()*(getWorkHour()-160)*1.5 + 100;}return getHourlyPayment()*160 + getHourlyPayment()*(getWorkHour()-160)*1.5;}else{if (this.getMonth() == month){return getWorkHour()*getHourlyPayment() + 100;}return getHourlyPayment()*getWorkHour();}}//constructorpublic HourlyEmployee() {}public HourlyEmployee(String name, int month, int hourlyPayment, int workHour) {super(name, month);this.hourlyPayment = hourlyPayment;this.workHour = workHour;}//setter and getterpublic int getHourlyPayment() {return hourlyPayment;}public void setHourlyPayment(int hourlyPayment) {this.hourlyPayment = hourlyPayment;}public int getWorkHour() {return workHour;}public void setWorkHour(int workHour) {this.workHour = workHour;}}/*SalesEmployee:Employee 的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率*/class SalesEmployee extends Employee{private double monthlySale;//提成率应在0~1之间private double commissionRate;//constructorpublic SalesEmployee() {}public SalesEmployee(String name, int month, double monthlySale, double commissionRate) {super(name, month);this.monthlySale = monthlySale;missionRate = commissionRate;}//setter and getterpublic double getMonthlySale() {return monthlySale;}public void setMonthlySale(double monthlySale) {this.monthlySale = monthlySale;}public double getCommissionRate() {return commissionRate;}public void setCommissionRate(double commissionRate) {missionRate = commissionRate;}@Overridepublic double getSalary(int month) {if (this.getMonth() == month){return this.getMonthlySale()*this.getCommissionRate() + 100;}else{return this.getMonthlySale()*this.getCommissionRate();}}}/*BasePlusSalesEmployee:SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。属性:底薪。*/class BasePlusSalesEmployee extends SalesEmployee{private double baseSalary;//constructorpublic BasePlusSalesEmployee() {}public BasePlusSalesEmployee(String name, int month, double monthlySale, double commissionRate, double baseSalary) {super(name, month, monthlySale, commissionRate);this.baseSalary = baseSalary;}//setter and getterpublic double getBaseSalary() {return baseSalary;}public void setBaseSalary(double baseSalary) {this.baseSalary = baseSalary;}//重写父类获得薪水的方法@Overridepublic double getSalary(int month) {if (this.getMonth() == month){return this.getBaseSalary() + this.getMonthlySale()*this.getCommissionRate() + 100;}else{return this.getBaseSalary() + this.getMonthlySale()*this.getCommissionRate();}}}

某公司的雇员分为以下若干类: Employee:这是所有员工总的父类属性: 员工的姓名 员工的生日月份。 方法:getSalary(

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。