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

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

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

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

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

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

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

Employee:
    这是所有员工总的父类,
    属性:员工的姓名,员工的生日月份

package com.baidu.zuoye;

/**
 * Employee:
 *     这是所有员工总的父类,
 *     属性:员工的姓名,员工的生日月份。
 *     方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
 */
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:
    Employee的子类,拿固定工资的员工。
    属性:月薪

package com.baidu.zuoye;
/**
 * SalariedEmployee:
 *     Employee的子类,拿固定工资的员工。
 *     属性:月薪
 */
public class SalariedEmployee extends Employee{
    private int yx;

        public SalariedEmployee(int yx) {
        this.yx = yx;
    }

    public SalariedEmployee(String name, int month, int yx) {
        super(name, month);
        this.yx = yx;
    }

    public int getYx() {
        return yx;
    }
    public void setYx(int yx) {
        this.yx = yx;
    }
    @Override
    public int getSalary(int month) {
        if (month == getMonth()){
            return getYx()+100;
        }else {
            return getYx();
        }
    }
}

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

package com.baidu.zuoye;

/**
 * HourlyEmployee:
 *     Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
 *     属性:每小时的工资、每月工作的小时数
 */
public class HourlyEmployee extends Employee {
    private int mxsgz;
    private int mygzxss;

    public HourlyEmployee(int mxsgz, int mygzxss) {
        this.mxsgz = mxsgz;
        this.mygzxss = mygzxss;
    }

    public HourlyEmployee(String name, int month, int mxsgz, int mygzxss) {
        super(name, month);
        this.mxsgz = mxsgz;
        this.mygzxss = mygzxss;
    }

    public int getMxsgz() {
        return mxsgz;
    }

    public void setMxsgz(int mxsgz) {
        this.mxsgz = mxsgz;
    }

    public int getMygzxss() {
        return mygzxss;
    }

    public void setMygzxss(int mygzxss) {
        this.mygzxss = mygzxss;
    }

    public int getSalary(int month) {
        if (getMygzxss() > 160) {
            if (month == getMonth()) {
                double v = (getMygzxss() - 160) * (1.5 * getMxsgz());
                int i = getMxsgz() * 160;
                return (int) (v + i + 100);
            }else {
                double v = (getMygzxss() - 160) * (1.5 * getMxsgz());
                int i = getMxsgz() * 160;
                return (int) (v + i);
            }
        } else {
            if (month == getMonth()) {
                int i = (getMxsgz() * getMygzxss()) + 100;
                return i;
            } else {
                int i = getMxsgz() * getMygzxss();
                return i;
            }
        }
    }
}

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

package com.baidu.zuoye;
/**
 * SalesEmployee:
 *     Employee的子类,销售人员,工资由月销售额和提成率决定。
 *     属性:月销售额、提成率
 */
public class SalesEmployee extends Employee {
    private int yxse;
    private double tcl;

    public SalesEmployee(int yxse, double tcl) {
        this.yxse = yxse;
        this.tcl = tcl;
    }
    public SalesEmployee(String name, int month, int yxse, double tcl) {
        super(name, month);
        this.yxse = yxse;
        this.tcl = tcl;
    }
    public int getYxse() {
        return yxse;
    }
    public void setYxse(int yxse) {
        this.yxse = yxse;
    }
    public double getTcl() {
        return tcl;
    }
    public void setTcl(double tcl) {
        this.tcl = tcl;
    }

    @Override
    public int getSalary(int month) {
        if (month == getMonth()) {
            double v = (getYxse() * getTcl());
            int v1 = (int) v + 100;
            return v1;
        } else {
            double v = (getYxse() * getTcl());
            return (int) v;
        }

    }
}

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

package com.baidu.zuoye;

/**
 * BasePlusSalesEmployee:
 *     SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。
 *     属性:底薪。
 */
public class BasePlusSalesEmployee extends SalesEmployee{  //有固定底薪的销售人员
    private int dx;

    public BasePlusSalesEmployee(int yxse, double tcl, int dx) {
        super(yxse, tcl);
        this.dx = dx;
    }
    public BasePlusSalesEmployee(String name, int month, int yxse, double tcl, int dx) {
        super(name, month, yxse, tcl);
        this.dx = dx;
    }

    public int getDx() {
        return dx;
    }
    public void setDx(int dx) {
        this.dx = dx;
    }

    @Override
    public int getSalary(int month) {
        if (month == getMonth()){
            double v = getDx() + (getYxse() * getTcl());
            return (int) (v+100);
        }else {
            double v = getDx() + (getYxse() * getTcl());
            return (int) v;
        }
    }
}

运行结果

小利的月薪是:8500
小张的月薪是:8150
小周的月薪是:8100
小付的月薪是:8860

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值