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

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

时间:2018-11-12 13:03:51

相关推荐

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

某公司的雇员分为以下若干类:

Employee:这是所有员工总的父类,

属性:

员工的姓名,员工的生日月份。

方法:getSalary(intmonth)

根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。

SalariedEmployee:

Employee 的子类,拿固定工资的员工。

属性:月薪

HourlyEmployee:

Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。

属性:每小时的工资、每月工作的小时数

SalesEmployee:

Employee 的子类,销售人员,工资由月销售额和提成率决定。

属性:月销售额、提成率

BasePlusSalesEmployee:

SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。

属性:底薪。

根据要求创建 SalariedEmployee 、 HourlyEmployees 、SaleEmployee 和 BasePlusSalesEmployee四个类的对象各一个,

并计算某个月这四个对象的工资。

注意:要求把每个类都做成完全封装,不允许非私有化属性。

主方法main:

public class Test {public static void main(String[] args) { //主方法mainEmployee salariedEmployee = new SalariedEmployee("小月",10,5000);Employee hourlyEmployee = new HourlyEmployee("小花",10,10,180);Employee salesEmployee = new SalesEmployee("小明",6,2000,2);Employee basePlusSalesEmployee = new BasePlusSalesEmployee("小艾",5,1000,2,3000);int salary = salariedEmployee.getSalary(10); //是生日的工资System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);/*int salary = salariedEmployee.getSalary(10); //不是生日的工资System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);*/int salary1 = hourlyEmployee.getSalary(10); //是生日的工资System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);/*int salary1 = hourlyEmployee.getSalary(2); //不是生日的工资System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);*/int salary2 = salesEmployee.getSalary(6); // 是生日的工资System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);/*int salary2 = salesEmployee.getSalary(3); // 是生日的工资System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);*/int salary3 = basePlusSalesEmployee.getSalary(5);//是生日工资System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);/*int salary3 = basePlusSalesEmployee.getSalary(3);//不是生日工资System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);*/}}

员工总的父类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 int getSalary(int month){ //让子类去重写return 0;}}

子类SalariedEmployee:

/*SalariedEmployee:Employee 的子类,拿固定工资的员工。属性:月薪*/public class SalariedEmployee extends Employee{ //拿固定工资的员工private int yueXin;public SalariedEmployee(int yueYin) {this.yueXin = yueYin;}public SalariedEmployee(String name, int month, int yueXin) {super(name, month);this.yueXin = yueXin;}public int getYueXin() {return yueXin;}public void setYueXin(int yueXin) {this.yueXin = yueXin;}@Overridepublic int getSalary(int month) {if (month == getMonth()){return getYueXin()+100;}else {return getYueXin();}}}

子类HourlyEmployee:

/*HourlyEmployee:Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。属性:每小时的工资、每月工作的小时数*/public class HourlyEmployee extends Employee { //按小时拿工资的员工private int meiXiaoShiGongZi;private int meiYueGongZuoXiaoShiSshu;public HourlyEmployee(int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {this.meiXiaoShiGongZi = meiXiaoShiGongZi;this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;}public HourlyEmployee(String name, int month, int meiXiaoShiGongZi, int meiYueGongZuoXiaoShiSshu) {super(name, month);this.meiXiaoShiGongZi = meiXiaoShiGongZi;this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;}public int getMeiXiaoShiGongZi() {return meiXiaoShiGongZi;}public void setMeiXiaoShiGongZi(int meiXiaoShiGongZi) {this.meiXiaoShiGongZi = meiXiaoShiGongZi;}public int getMeiYueGongZuoXiaoShiSshu() {return meiYueGongZuoXiaoShiSshu;}public void setMeiYueGongZuoXiaoShiSshu(int meiYueGongZuoXiaoShiSshu) {this.meiYueGongZuoXiaoShiSshu = meiYueGongZuoXiaoShiSshu;}public int getSalary(int month) {if (getMeiYueGongZuoXiaoShiSshu() > 160) {if (month == getMonth()) {double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());int i = getMeiXiaoShiGongZi() * 160;return (int) (v + i + 100);}else {double v = (getMeiYueGongZuoXiaoShiSshu() - 160) * (1.5 * getMeiXiaoShiGongZi());int i = getMeiXiaoShiGongZi() * 160;return (int) (v + i);}} else {if (month == getMonth()) {int i = (getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu()) + 100;return i;} else {int i = getMeiXiaoShiGongZi() * getMeiYueGongZuoXiaoShiSshu();return i;}}}}

子类SalesEmployee: 销售人员

/*SalesEmployee:Employee 的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率*/public class SalesEmployee extends Employee { //销售人员,工资由月销售额和提成率决定private int yueXiaoShouE;private double tiChengLv;public SalesEmployee(int yueXiaoShouE, double tiChengLv) {this.yueXiaoShouE = yueXiaoShouE;this.tiChengLv = tiChengLv;}public SalesEmployee(String name, int month, int yueXiaoShouE, double tiChengLv) {super(name, month);this.yueXiaoShouE = yueXiaoShouE;this.tiChengLv = tiChengLv;}public int getYueXiaoShouE() {return yueXiaoShouE;}public void setYueXiaoShouE(int yueXiaoShouE) {this.yueXiaoShouE = yueXiaoShouE;}public double getTiChengLv() {return tiChengLv;}public void setTiChengLv(double tiChengLv) {this.tiChengLv = tiChengLv;}@Overridepublic int getSalary(int month) {if (month == getMonth()) {double v = (getYueXiaoShouE() * getTiChengLv());int v1 = (int) v + 100;return v1;} else {double v = (getYueXiaoShouE() * getTiChengLv());return (int) v;}}}

子类:BasePlusSalesEmployee

/*BasePlusSalesEmployee:SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。属性:底薪。*/public class BasePlusSalesEmployee extends SalesEmployee{ //有固定底薪的销售人员private int diXin;public BasePlusSalesEmployee(int yueXiaoShouE, double tiChengLv, int diXin) {super(yueXiaoShouE, tiChengLv);this.diXin = diXin;}public BasePlusSalesEmployee(String name, int month, int yueXiaoShouE, double tiChengLv, int diXin) {super(name, month, yueXiaoShouE, tiChengLv);this.diXin = diXin;}public int getDiXin() {return diXin;}public void setDiXin(int diXin) {this.diXin = diXin;}@Overridepublic int getSalary(int month) {if (month == getMonth()){double v = getDiXin() + (getYueXiaoShouE() * getTiChengLv());return (int) (v+100);}else {double v = getDiXin() + (getYueXiaoShouE() * getTiChengLv());return (int) v;}}}

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

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