java-继承,编程:某公司的雇员分为以下若干类:

(1) Employee :这是所有员工总的父类。
属性:员工的姓名,员工的生日月份
方法: getSalary(int month)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元.
(2)SalariedEmployee : Employee 的子类,拿固定工资的员工。
属性∶月薪。
(3)HourlyEmployee : Employee 的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性︰每小时的工资、每月工作的小时数。
(4) SalesEmployee : Employee 的子类,销售,工资由月销售额和提成率决定。
属性:月销售额、提成率.
(5)BasePlusSalesEmployee : SalesEmployee 的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。。
属性:底薪.
要求:
(1)创建SalariedEmployee、HourlyEmployee、SaleEmployee、BasePlusSalesEmployee四个类的对象各一个
(2)并调用父类getSalary(int money)方法计算某个月这四个对象各自的工资
注意:要求把每个类都做成完全封装,不允许非私有化属性。
编程∶在上一题的基础上,创建一个Employee 数组,分别创建若干不同的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;
    }

    public double getSalary(int month) {
        if (month == this.month) {
            return 100;
        }
        return 0;
    }

}

class SalariedEmployee extends Employee {
    private double salary;

    public SalariedEmployee() {
    }

    public SalariedEmployee(double salary) {
        this.salary = salary;
    }

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

    public double getSalary() {
        return salary;
    }

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

    @Override
    public double getSalary(int month) {
        return super.getSalary(month) + salary;
    }

}

class HourlyEmployee extends Employee {
    private double hourlySalary;
    private int hours;

    public HourlyEmployee() {
    }

    public HourlyEmployee(double hourlySalary, int hours) {
        this.hourlySalary = hourlySalary;
        this.hours = hours;
    }

    public HourlyEmployee(String name, int month, double hourlySalary, int hours) {
        super(name, month);
        this.hourlySalary = hourlySalary;
        this.hours = hours;
    }

    public double getHourlySalary() {
        return hourlySalary;
    }

    public void setHourlySalary(double hourlySalary) {
        this.hourlySalary = hourlySalary;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    @Override
    public double getSalary(int month) {
        if (hours <= 160) {
            return super.getSalary(month) + hourlySalary * hours;
        } else {
            return super.getSalary(month) + (hours - 160) * 1.5 * hourlySalary + 160 * hourlySalary;
        }
    }
}

class SalesEmployee extends Employee {
    private double sales;//月销额
    private double rate;//提出率

    public SalesEmployee() {
    }

    public SalesEmployee(double sales, double rate) {
        this.sales = sales;
        this.rate = rate;
    }

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

    public double getSales() {
        return sales;
    }

    public void setSales(double sales) {
        this.sales = sales;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    @Override
    public double getSalary(int month) {
        return super.getSalary(month) + sales + rate;
    }
}

class BasePlusSalesEmployee extends SalesEmployee {
    private double baseSalesEmployee;

    public BasePlusSalesEmployee() {
    }

    public BasePlusSalesEmployee(double baseSalesEmployee) {
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public BasePlusSalesEmployee(double sales, double rate, double baseSalesEmployee) {
        super(sales, rate);
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public BasePlusSalesEmployee(String name, int month, double sales, double rate, double baseSalesEmployee) {
        super(name, month, sales, rate);
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public double getBaseSalesEmployee() {
        return baseSalesEmployee;
    }

    public void setBaseSalesEmployee(double baseSalesEmployee) {
        this.baseSalesEmployee = baseSalesEmployee;
    }

    @Override
    public double getSalary(int month) {
        return super.getSalary(month)+baseSalesEmployee;
    }
}
class TestEmployee{
    public static void main(String[] args) {
        SalariedEmployee salariedEmployee = new SalariedEmployee("张三",1,4000);
        System.out.println(salariedEmployee.getSalary(2));

        HourlyEmployee hourlyEmployee = new HourlyEmployee("李四",3,40,165);
        System.out.println(hourlyEmployee.getSalary(3));

        SalesEmployee salesEmployee = new SalesEmployee("王五",6,3000,4000);
        System.out.println(salesEmployee.getSalary(9));

        BasePlusSalesEmployee basePlusSalesEmployee = new BasePlusSalesEmployee("杰克",9,3500,1000,2000);
        System.out.println(basePlusSalesEmployee.getSalary(5));

        System.out.println("打印个员工五月的工资:");
        Employee[] employee = new Employee[]{salariedEmployee,hourlyEmployee,salesEmployee,basePlusSalesEmployee};
        for (int i=0;i<employee.length;i++){
            System.out.println(employee[i].getSalary(5));
        }
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MaGgIeOo0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值