员工工资表

package work.eleven;

/*
*  这是所有员工总的父类,
    属性:员工的姓名,员工的生日月份。
    方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
* */
public class Employee {
    private int monthN = 12;//假设现在12月
    private int month;
    private int salary = 100;

    public Employee() {
        setMonth(month);
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public double getSalary() {
        if (monthN == month) {
            return salary;
        } else return 0;
    }
}
 
package work.eleven;

/*
*   Employee的子类,拿固定工资的员工。
    属性:月薪
* */
public class SalariedEmployee extends Employee {
    private double salary;

    public SalariedEmployee(double salary) {
        // TODO Auto-generated constructor stub
        super();
        setSalary(salary);
    }

    @Override
    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
}
package work.eleven;

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

    public HourlyEmployee(double timeSalary, int time) {
        super();
        setTime(time);
        setTimeSalary(timeSalary);
    }

    @Override
    public double getSalary() {
        if (time > 160) {
            return 160 * timeSalary + (time - 160) * 1.5 * timeSalary;
        }else
            return time * timeSalary;
    }

    public double getTimeSalary() {
        return timeSalary;
    }

    public void setTimeSalary(double timeSalary) {
        this.timeSalary = timeSalary;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
}
package work.eleven;

/*
* Employee的子类,销售人员,工资由月销售额和提成率决定。
    属性:月销售额、提成率
* */
public class SalesEmployee extends Employee{
    private double sale;//月销售额
    private double addRate;//提成


    public SalesEmployee(double sale, double addRate) {
        setAddRate(addRate);
        setSale(sale);

    }

    @Override
    public double getSalary() {
        // TODO Auto-generated method stub
        return sale * addRate;
    }

    public double getSale() {
        return sale;
    }

    public void setSale(double sale) {
        this.sale = sale;
    }

    public double getAddRate() {
        return addRate;
    }

    public void setAddRate(double addRate) {
        this.addRate = addRate;
    }
}
package work.eleven;

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

    public BasePlusSalesEmployee(double sale, double addRate, double baseSalary) {
        super(sale, addRate);
        // TODO Auto-generated constructor stub
        setAddRate(addRate);
        setBaseSalary(baseSalary);
        setSale(sale);
    }

    @Override
    public double getSalary() {
        SalesEmployee a = new SalesEmployee(sale, addRate);
        // TODO Auto-generated method stub
        return baseSalary + a.getSalary();
    }

    public double getBaseSalary() {
        return baseSalary;
    }

    public void setBaseSalary(double baseSalary) {
        this.baseSalary = baseSalary;
    }

    @Override
    public double getAddRate() {
        return addRate;
    }

    @Override
    public void setAddRate(double addRate) {
        this.addRate = addRate;
    }

    @Override
    public double getSale() {
        return sale;
    }

    @Override
    public void setSale(double sale) {
        this.sale = sale;
    }
}
package work.eleven;

import java.util.Calendar;

/*
* 写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
* */
public class Test {
    public static void main(String[] args) {
        Employee employee[] = {
                new SalariedEmployee(1000),
                new HourlyEmployee(16, 150),
                new SalesEmployee(500, 1),
                new BasePlusSalesEmployee(500, 1, 1000)
        };
        Calendar cal = Calendar.getInstance();
        cal.set(2020, 12, 20);
        for (int i = 0; i < employee.length; i++) {
            int month = cal.get(Calendar.MONTH);
            Employee a = new Employee();
            a.setMonth(month);
            double welfare = a.getSalary();
            double salary = employee[i].getSalary();
            System.out.println("第" + (i + 1) + "个员工工资为:" + (welfare + salary));
        }
    }

}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值