员工类工资

创建父类

package com.ytzl.chapter04.wjt.one;

/**
 * Create with IntelliJ IDEA.
 * Description:
 * User: 稚萱
 * Author 86185
 * Date: 2022-03-18
 * Time: 14:21
 */
public abstract class Employee {
    private String name;//名字
    private int WorkNumber;//工号
    private double bonus;//奖金

    public Employee() {
    }

    public Employee(String name, int workNumber, double bonus) {
        this.name = name;
        WorkNumber = workNumber;
        this.bonus = bonus;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWorkNumber() {
        return WorkNumber;
    }

    public void setWorkNumber(int workNumber) {
        WorkNumber = workNumber;
    }

    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;
    }
    //计算奖金的方法
    public abstract double calcuBonus();

    @Override
    public String toString() {
        return "Employee{" +
                "我的名字为:='" + name + '\'' +
                ", 我的工号为:=" + WorkNumber +
                ", 我的工资为:=" + bonus +
                '}';
    }
}

员工类

package com.ytzl.chapter04.wjt.one;

/**
 * Create with IntelliJ IDEA.
 * Description:
 * User: 稚萱
 * Author 86185
 * Date: 2022-03-18
 * Time: 14:29
 */
public class OrdinaryEmployees extends Employee{
    private double ordinaryEmployees=0.015;

    public OrdinaryEmployees() {
    }

    public OrdinaryEmployees(String name, int workNumber, double bonus) {
        super(name, workNumber, bonus);
    }

    public double getOrdinaryEmployees() {
        return ordinaryEmployees;
    }

    public void setOrdinaryEmployees(double ordinaryEmployees) {
        this.ordinaryEmployees = ordinaryEmployees;
    }

    @Override
    public double calcuBonus() {
            return super.getBonus()*getOrdinaryEmployees();
    }

    @Override
    public String toString() {
        System.out.println(super.toString());
        return "OrdinaryEmployees{" +
                "我的奖金为=" + ordinaryEmployees*super.getBonus() +
                '}';
    }
}

经理类

package com.ytzl.chapter04.wjt.one;

/**
 * Create with IntelliJ IDEA.
 * Description:
 * User: 稚萱
 * Author 86185
 * Date: 2022-03-18
 * Time: 14:29
 */
public class TheManager extends Employee{
    private double TheManager=0.02;

    public TheManager() {
    }

    public double getOrdinaryEmployees() {
        return TheManager;
    }

    public void setOrdinaryEmployees(double TheManager) {
        this.TheManager = TheManager;
    }

    public TheManager(double TheManager) {
        this.TheManager = TheManager;
    }

    public TheManager(String name, int workNumber, double bonus) {
        super(name, workNumber, bonus);
    }

    @Override
    public double calcuBonus() {
            return super.getBonus()*getOrdinaryEmployees();
    }

    @Override
    public String toString() {
        System.out.println(super.toString());
        return "TheManager{" +
                "我的奖金为:=" + TheManager*super.getBonus() +
                '}';
    }
}

老板类

package com.ytzl.chapter04.wjt.one;

/**
 * Create with IntelliJ IDEA.
 * Description:
 * User: 稚萱
 * Author 86185
 * Date: 2022-03-18
 * Time: 14:40
 */
public class Boss {
        public  double totalSalary(Employee[] employee){
            double totalSalary=0;
            for (int i = 0; i < employee.length; i++) {
                double bonus = employee[i].calcuBonus() * 12;
                double wages = employee[i].getBonus() * 12;
                        totalSalary+=bonus+wages;
            }

            return totalSalary;
        }
}

测试类

package com.ytzl.chapter04.wjt.one;

/**
 * Create with IntelliJ IDEA.
 * Description:
 * User: 稚萱
 * Author 86185
 * Date: 2022-03-18
 * Time: 15:02
 */
public class Test {
    public static void main(String[] args) {
        OrdinaryEmployees pu1=new OrdinaryEmployees("王小王",1909144,500);
        OrdinaryEmployees pu2=new OrdinaryEmployees("王小",1909144,900);
        Boss boss = new Boss();
        OrdinaryEmployees[] employees = new OrdinaryEmployees[2];
        employees[0]=pu1;
        System.out.println(pu1.toString());
        employees[1]=pu2;
        System.out.println(boss.totalSalary(employees));
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值