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

某公司的雇员分为以下若干类:
Employee:
    这是所有员工总的父类,
    属性:员工的姓名,员工的生日月份。
    方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。

SalariedEmployee:
    Employee的子类,拿固定工资的员工。
    属性:月薪

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

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

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

写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
*注意:要求把每个类都封装,不允许非私有化属性。

Employee类:

package com.hp;

public class Employee {
    private String name;
    private int month;
    private double salary;
    //无参构造函数
    public Employee(){
    }
    //有参构造函数
    public Employee(String name,int month,double salary){
        this.name=name;
        this.month=month;
        this.salary=salary;
    }
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
    public void setMonth(int month){
        this.month=month;
    }
    public int getMonth(){
        return month;
    }
    public void setSalary(double salary){
        this.salary=salary;
    }
    public double getSalary(){
        return salary;
    }

    public double getSalary(int month) {
        if (this.month == month) {
            salary += 100;
        }
        System.out.println("员工" + getName() + "的薪水为:" + salary);
        return salary;
    }
}

SalariedEmployee:

package com.hp;

public class SalariedEmployee extends Employee{
    private double salary1;
    //无参构造函数
    public  SalariedEmployee(){

    }
    //有参构造函数
    public  SalariedEmployee(double salary1){
        this.salary1=salary1;
    }
    public void setSalary1(double salary1){
        this.salary1=salary1;
    }
    public double getSalary1(){
        return salary1;
    }

    public double getSalary(int month){
        if(this.getMonth() == month){
            salary1 += 100;
        }
        System.out.println("该员工"+getName()+"的薪水为:"+salary1);
        return salary1;
    }

}

HourlyEmployee:

package com.hp;

public class HourlyEmployee extends Employee{
    private int hour;
    private double price;
    private double salary2;
    //无参构造函数
    public  HourlyEmployee(){

    }
    //有参构造函数
    public  HourlyEmployee(int hour,double price,double salary2){
        this.hour=hour;
        this.price=price;
        this.salary2=salary2;
    }
    public void setHour(int hour){
        this.hour=hour;
    }
    public int getHour(){
        return hour;
    }
    public void setPrice(double price){
        this.price=price;
    }
    public double getPrice(){
        return price;
    }
    public void setSalary2(double salary2){
        this.salary2=salary2;
    }
    public double getSalary2(){
        return salary2;
    }

    public double getSalary(int month){
        if( hour <= 160){
            salary2=price * hour;
        }else{
            hour=hour-160;
            salary2=160 * price + hour *1.5*price;
        }
        if(getMonth() == month){
            salary2+=100;
        }
        System.out.println("该员工"+getName()+"的薪水为:"+salary2);
        return salary2;
    }


}

SalesEmployee:

package com.hp;

public class SalesEmployee extends Employee{
    private double salemonth;
    private double rate;
    //构造器
    public  SalesEmployee(){
    }
    public SalesEmployee(double salemonth,double rate){
        this.salemonth=salemonth;
        this.rate=rate;
    }
    public void setSalemonth(double salemonth){
        this.salemonth=salemonth;
    }
    public double getSalemonth(){
        return salemonth;
    }
    public void setRate(double rate){
        this.rate=rate;
    }
    public double getRate(){
        return rate;
    }
    public double getSalary(int month){
        if(this.getMonth() == month){
            System.out.println("该员工"+getName()+"的薪水为:"+(100+salemonth*rate));
            return (salemonth * rate)+100;
        }else{
            System.out.println("该员工"+getName()+"的薪水为:"+salemonth * rate);
            return salemonth * rate;
        }
    }
}

BasePlusSalesEmployee:

package com.hp;

public class BasePlusSalesEmployee extends Employee{
    private double minsalary;
    private double salemonth1;
    private double rate1;
    //构造器
    public  BasePlusSalesEmployee(){
    }
    public BasePlusSalesEmployee(double minsalary,double salemonth1,double rate1){
        this.minsalary=minsalary;
        this.salemonth1=salemonth1;
        this.rate1=rate1;
    }
    public void setMinsalary(double minsalary){
        this.minsalary=minsalary;
    }
    public double getMinsalary(){
        return minsalary;
    }
    public void setSalemonth1(double salemonth1){
        this.salemonth1=salemonth1;
    }
    public double getSalemonth1(){
        return salemonth1;
    }
    public void setRate1(double rate1){
        this.rate1=rate1;
    }
    public double getRate1(){
        return rate1;
    }
    public double getSalary(int month){
        if(this.getMonth() == month){
            System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1+100));
            return minsalary+salemonth1*rate1+100;
        }
        System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1));
        return minsalary+salemonth1*rate1;
    }
}

测试类:

package com.hp;

public class Test {
    public static void main(String[] args) {
        Employee e1 = new Employee("小王", 5, 0);
        e1.setSalary(6);
        SalariedEmployee s1 = new SalariedEmployee();
        s1.setName("张三");
        s1.setSalary1(5500);
        s1.setMonth(6);
        s1.getMonth();
        s1.getSalary(4);
        HourlyEmployee h1 = new HourlyEmployee(192,36,0);
        h1.setName("李四");
        h1.setMonth(6);
        h1.getMonth();
        h1.getSalary(6);
        SalesEmployee ss1 = new SalesEmployee(26000,0.4);
        ss1.setName("王麻子");
        ss1.setMonth(9);
        ss1.getMonth();
        ss1.getSalary(6);

        BasePlusSalesEmployee b1 =new BasePlusSalesEmployee(3000,9000,0.5);
        b1.setName("赵六");
        b1.setMonth(9);
        b1.getMonth();
        System.out.println("输出赵六的生日月份:"+b1.getMonth());
        b1.getSalary(9);
}
}

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值