员工工资。

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

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

BasePlusSalesEmployee:

public class BasePlusSalesEmployee extends SalesEmployee {
    private int dixin;

    public BasePlusSalesEmployee(int yuexiaoshou, double ticheng, int dixin) {
        super(yuexiaoshou, ticheng);
        this.dixin = dixin;
    }

    public BasePlusSalesEmployee(String name, int month, int yuexiaoshou, double ticheng, int dixin) {
        super(name, month, yuexiaoshou, ticheng);
        this.dixin = dixin;
    }

    public int getDixin() {
        return dixin;
    }

    public void setDixin(int dixin) {
        this.dixin = dixin;
    }

    public int getSalary(int month) {
        if (month == getMonth()) {
            double b = getDixin() + (getYuexiaoshou() * getTicheng());
            return (int) (b + 100);

        } else {
            double b = getDixin() + (getYuexiaoshou() * getTicheng());
            return (int) b;
        }
    }
}


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;
    }
}

HourlyEmployee:
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;
            }
        }
    }
}
SalariedEmployee:
public class SalariedEmployee extends Employee{
    private  int yuexin;

    public SalariedEmployee(int yuexin){
        this.yuexin= yuexin;
    }
    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;
    }
    public  int getSalary(int month) {
        if (month == getMonth()) {
            return getYuexin()+100;
            }
                return getYuexin();
            }
        }

SalesEmployee:
public class SalesEmployee extends Employee{
    private int yuexiaoshou;
    private  double ticheng;

    public SalesEmployee(int yuexiaoshou, double ticheng) {
        this.yuexiaoshou = yuexiaoshou;
        this.ticheng = ticheng;
    }

    public SalesEmployee(String name, int month, int yuexiaoshou, double ticheng) {
        super(name, month);
        this.yuexiaoshou = yuexiaoshou;
        this.ticheng = ticheng;
    }

    public int getYuexiaoshou() {
        return yuexiaoshou;
    }

    public void setYuexiaoshou(int yuexiaoshou) {
        this.yuexiaoshou = yuexiaoshou;
    }

    public double getTicheng() {
        return ticheng;
    }

    public void setTicheng(double ticheng) {
        this.ticheng = ticheng;
    }
    public  int getSalary(int month){
        if (month == getMonth()) {
            double a = (getYuexiaoshou() * getTicheng());
            int a1 = (int)  a + 100;
            return a1;
        }else {
            double a = (getYuexiaoshou() * getTicheng());
            return (int) a;
        }
    }
}

 Test:
public class Test {
    public static void main(String[] args) {
        Employee 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) salariedEmployee).getSalary(10);  
        System.out.println(salariedEmployee.getName()+"的月薪是:" + salary);
       

        int salary1 = ((HourlyEmployee) hourlyEmployee).getSalary(10); 
        System.out.println(hourlyEmployee.getName()+"的月薪是:" + salary1);
        

        int salary2 = ((SalesEmployee) salesEmployee).getSalary(6);
        System.out.println(salesEmployee.getName()+"的月薪是:" + salary2);
      

        int salary3 = ((BasePlusSalesEmployee) basePlusSalesEmployee).getSalary(5);
        System.out.println(basePlusSalesEmployee.getName()+"的月薪是:" + salary3);
      


    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值