某公司的雇员分为以下若干类: Employee:这是所有员工总的父类, 属性: 员工的姓名,员工的生日月份。 方法:getSalary(
代码
/*某公司的雇员分为以下若干类: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;this.commissionRate = 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) {this.commissionRate = 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(相关推荐
- Cola公司的雇员分为以下若干类:(知识点:多态) 4.1 ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工 的生日月份。方法:getSalary(int month) 根据
Cola公司的雇员分为以下若干类:(知识点:多态) 4.1 ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工 的生日月份.方法:getSalary(int month) 根据参 ...
- 某公司的雇员分为以下若干类:
某公司的雇员分为以下若干类: Employee: 这是所有员工总的父类, 属性:员工的姓名,员工的生日月份. 方法:getSalary(int month) 根据参数月份来确定工资,如果该 ...
- 某公司的雇员分为以下若干类;
某公司的雇员分为以下若干类: Employee:这是所有员工总的父类, 属性:员工的姓名,员工的生日月份. 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日, ...
- 某公司的雇员分为以下若干类 7-12
题目:某公司的雇员分为以下若干类写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额. 注意:要求把每个类都封装,不允许非私有化属性. Employ ...
- # 封装,抽象类,继承,重写java编程题 问题描述 ``` 某公司的雇员分为以下若干类: Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。 方法:getSalary(int
封装,抽象类,继承,重写java编程题 问题描述 某公司的雇员分为以下若干类: Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份. 方法:getSalary(int month ...
- java编程---某公司的雇员分为以下若干类:Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(intmonth)根据参数月份来确定工资。
题目: 某公司的雇员分为以下若干类: Employee:这是所有员工总的父类, 属性: 员工的姓名,员工的生日月份. 方法:getSalary(intmonth) 根据参数月份来确定工资,如果该月员工 ...
- (1)定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个 findArea()方法返回圆的面积。 (2)定义一个类PassObject,在类中定义一个方法printA
(1)定义一个 Circle 类,包含一个 double 型的 radius 属性代表圆的半径,一个 findArea() 方法返回圆的面积. ( 2 )定义一个类 PassObject ,在类中 ...
- 某公司员工分为若干类
某公司的雇员分为以下若干类: Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份. 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则 ...
- 四边形可以分为几类_大件物流有哪些公司?大件物流公司的业务可以分为哪几类...
随着电商市场规模不断扩张,货运渠道,物流公司需求尤为明显,大件物流公司为满足市场需求,大件物流服务需求更是大幅增加,吸引了不少快运企业开始进行竞争.接下来我们就来聊聊大件物流有哪些公司?大件物流行业趋 ...
最新文章
- 设计模式之八大设计原则
- LMDIF_函数用法
- k8s pod重启策略:Always、OnFailure、Never配置示例
- linux gnome 桌面,GNOME Linux桌面
- ES6中的迭代器(Iterator)和生成器(Generator)(一)
- 删除悬镜linux安装教程,Linux安全运维之如何活用history命令
- 量化金融笔记2-期货量化基础
- 内蒙古等保测评机构项目测评收费价格标准参考
- python发微信消息_利用python实现微信消息自动提醒
- 反脆弱性:为什么工作越稳定,人生越脆弱?
- 使用Python获取股市北向资金和南向资金信息
- Problem -B DBZ的钥匙
- 整理的部分TI AM4379嵌入式项目笔记
- python爬iptv直播源_GitHub - linnoreading/iptv-m3u: python 爬的直播源数据
- jquery实现图片上传
- 学计算机的,为什么要用linux?
- 做人要厚道,不要太冲
- 机器学习工程师与研究员之间的7个主要区别(包括薪水)
- 线性代数的本质(二)——线性组合、张成空间和基
- 对云端软件平台的印象