程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-06(3)

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

发布于2020-11-29 18:44     阅读(1277)     评论(0)     点赞(0)     收藏(0)


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

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

方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,

则公司会额外奖励100元。

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

HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160

小时的部分按照1.5倍工资发放

属性:每小时的工资、每月工作的小时数

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

属性:月销售额、提成率

BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,

工资由底薪加上销售提成部分     属性:底薪。

 

public class TestEmployee{

    public static void main(String[]args){

        Employee[] es = new Employee[5];

        es[0] = new Employee("赵君",2);

        es[1] = new SalariedEmployee("宋婕", 1, 8000);

        es[2] = new HourlyEmployee("王超", 5, 10, 300);

        es[3] = new SalesEmployee("秋娥", 2, 200000, 0.05);

        es[4] = new BaseSalarySalesEmployee("郭镫鸿", 1, 1000000, 0.1, 10000);

        int month = 2;//本月为2月

        System.out.println("宇宙集团"+month+"月工资表:");

        for(int i=0; i<es.length; i++){

            System.out.println(es[i].getName()+":"+es[i].getSalary(month));

        }

    }

}

 

class Employee{

    private String name;

    private int birth;

    public String getName(){

        return name;

    }

    public Employee(String name, int birth){

        this.name = name;

        this.birth = birth;

    }

    public double getSalary(int month){

        if(month==birth){

            return 100;

        }

        return 0;

    }

}

 

class SalariedEmployee extends Employee{

    private double salary;

    public SalariedEmployee(String name, int birth, double salary){

        super(name, birth);

        this.salary = salary;

    }

    public double getSalary(int month){

        return salary + super.getSalary(month);

    }

}

 

class HourlyEmployee extends Employee{

    private double hourSalary;

    private int hour;

    public HourlyEmployee(String name, int birth, double hourSalary, int hour){

        super(name, birth);

        this.hourSalary = hourSalary;

        this.hour = hour;

    }

    public double getSalary(int month){

        if(hour<=160){

            return hourSalary*hour+super.getSalary(month);

        }else{

            return 160*hourSalary+(hour-160)*hourSalary*1.5+super.getSalary(month);

        }

    }

}

 

class SalesEmployee extends Employee{

    private double sales;

    private double pre;

    public SalesEmployee(String name, int birth, double sales, double pre){

        super(name, birth);

        this.sales = sales;

        this.pre = pre;

    }

    public double getSalary(int month){

        return sales*pre+super.getSalary(month);

    }

}

 

class BaseSalarySalesEmployee extends SalesEmployee{

    private double baseSalary;

    public BaseSalarySalesEmployee(String name, int birth, double sales, double pre, double baseSalary){

        super(name, birth, sales, pre);

        this.baseSalary = baseSalary;

    }

    public double getSalary(int month){

        return baseSalary+super.getSalary(month);

    }

}

 



所属网站分类: java资源下载 > 其它资源

作者:天使之恋

链接:http://www.javaheidong.com/blog/article/13279/9a53c17274e862fec9e1/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)