发布于2020-11-29 18:44 阅读(1692) 评论(0) 点赞(0) 收藏(0)
某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,属性:员工的姓名和生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,
则公司会额外奖励100元。
SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160
小时的部分按照1.5倍工资发放
属性:每小时的工资、每月工作的小时数
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定
属性:月销售额、提成率
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,
工资由底薪加上销售提成部分 属性:底薪。
public class TestEmployee{
public static void main(String[]args){
Employee[] es = new Employee[5];
es[0] = new Employee("赵君",2);
es[1] = new SalariedEmployee("宋婕", 1, 8000);
es[2] = new HourlyEmployee("王超", 5, 10, 300);
es[3] = new SalesEmployee("秋娥", 2, 200000, 0.05);
es[4] = new BaseSalarySalesEmployee("郭镫鸿", 1, 1000000, 0.1, 10000);
int month = 2;//本月为2月
System.out.println("宇宙集团"+month+"月工资表:");
for(int i=0; i<es.length; i++){
System.out.println(es[i].getName()+":"+es[i].getSalary(month));
}
}
}
class Employee{
private String name;
private int birth;
public String getName(){
return name;
}
public Employee(String name, int birth){
this.name = name;
this.birth = birth;
}
public double getSalary(int month){
if(month==birth){
return 100;
}
return 0;
}
}
class SalariedEmployee extends Employee{
private double salary;
public SalariedEmployee(String name, int birth, double salary){
super(name, birth);
this.salary = salary;
}
public double getSalary(int month){
return salary + super.getSalary(month);
}
}
class HourlyEmployee extends Employee{
private double hourSalary;
private int hour;
public HourlyEmployee(String name, int birth, double hourSalary, int hour){
super(name, birth);
this.hourSalary = hourSalary;
this.hour = hour;
}
public double getSalary(int month){
if(hour<=160){
return hourSalary*hour+super.getSalary(month);
}else{
return 160*hourSalary+(hour-160)*hourSalary*1.5+super.getSalary(month);
}
}
}
class SalesEmployee extends Employee{
private double sales;
private double pre;
public SalesEmployee(String name, int birth, double sales, double pre){
super(name, birth);
this.sales = sales;
this.pre = pre;
}
public double getSalary(int month){
return sales*pre+super.getSalary(month);
}
}
class BaseSalarySalesEmployee extends SalesEmployee{
private double baseSalary;
public BaseSalarySalesEmployee(String name, int birth, double sales, double pre, double baseSalary){
super(name, birth, sales, pre);
this.baseSalary = baseSalary;
}
public double getSalary(int month){
return baseSalary+super.getSalary(month);
}
}
作者:天使之恋
链接:http://www.javaheidong.com/blog/article/13279/9a53c17274e862fec9e1/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!