某公司员工分为若干类

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

Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪。
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数。
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率。
BasedPlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,
工资由底薪加上销售提成部分。
属性:底薪。

第一个类//Employee类

public class Employee{

    private String name;

    private int month;

    private double salary;

    //无参构造函数

    public Employee(){

    }

    //有参构造函数

    public Employee(String name,int month,double salary){

        this.name=name;

        this.month=month;

        this.salary=salary;

    }

    public void setName(String name){

        this.name=name;

    }

    public String getName(){

        return name;

    }

    public void setMonth(int month){

        this.month=month;

    }

    public int getMonth(){

        return month;

    }

    public void setSalary(double salary){

        this.salary=salary;

    }

    public double getSalary(){

        return salary;

    }

    public double getSalary(int month){

        if(this.month == month){

            salary += 100;

        }

        System.out.println("员工"+ getName()+"的薪水为:"+salary);

        return salary;

    }

}

第二个类:

//SalariedEmployee类

public class SalariedEmployee extends Employee{

    private double salary1;

     //无参构造函数

    public  SalariedEmployee(){

    }

    //有参构造函数

    public  SalariedEmployee(double salary1){

        this.salary1=salary1;

    }

    public void setSalary1(double salary1){

        this.salary1=salary1;

    }

    public double getSalary1(){

        return salary1;

    }

    public double getSalary(int month){        

        if(this.getMonth() == month){

            salary1 += 100;

        }

        System.out.println("该员工"+getName()+"的薪水为:"+salary1);

        return salary1;

    }    

}

第三个类:

//HourlyEmployee类

public class HourlyEmployee extends Employee{

    private int hour;

    private double price;

    private double salary2;

    //无参构造函数

    public  HourlyEmployee(){

    }

    //有参构造函数

    public  HourlyEmployee(int hour,double price,double salary2){

        this.hour=hour;

        this.price=price;

        this.salary2=salary2;

    }

    public void setHour(int hour){

        this.hour=hour;

    }

    public int getHour(){

        return hour;

    }

    public void setPrice(double price){

        this.price=price;

    }

    public double getPrice(){

        return price;

    }

    public void setSalary2(double salary2){

        this.salary2=salary2;

    }

    public double getSalary2(){

        return salary2;

    }

    public double getSalary(int month){        

        if( hour <= 160){

            salary2=price * hour;

        }

        else{

            hour=hour-160;

            salary2=160 * price + hour *1.6*price;

        }

        if(getMonth() == month){

            salary2+=100;

        }

        System.out.println("该员工"+getName()+"的薪水为:"+salary2);

        return salary2;

    }

    

}

第四个类:

//SalesEmployee类

public class SalesEmployee extends Employee{

    private double salemonth;

    private double rate;

    //无参构造函数

    public  SalesEmployee(){

    }

    //有参构造函数

    public SalesEmployee(double salemonth,double rate){

        this.salemonth=salemonth;

        this.rate=rate;

    }

    public void setSalemonth(double salemonth){

        this.salemonth=salemonth;

    }

    public double getSalemonth(){

        return salemonth;

    }

    public void setRate(double rate){

        this.rate=rate;

    }

    public double getRate(){

        return rate;

    }

    public double getSalary(int month){

        if(this.getMonth() == month){

        System.out.println("该员工"+getName()+"的薪水为:"+(100+salemonth*rate));

        return (salemonth * rate)+100;

        }else{

        System.out.println("该员工"+getName()+"的薪水为:"+salemonth * rate);

        return salemonth * rate;

        }

    }

    

}

第五个类:

//BasePlusSalesEmployee类

public class BasePlusSalesEmployee extends Employee{

    private double minsalary;

    private double salemonth1;

    private double rate1;

    //无参构造函数

    public  BasePlusSalesEmployee(){

    }

    //有参构造函数

    public BasePlusSalesEmployee(double minsalary,double salemonth1,double rate1){

        this.minsalary=minsalary;

        this.salemonth1=salemonth1;

        this.rate1=rate1;

    }

    public void setMinsalary(double minsalary){

        this.minsalary=minsalary;

    }

    public double getMinsalary(){

        return minsalary;

    }

    public void setSalemonth1(double salemonth1){

        this.salemonth1=salemonth1;

    }

    public double getSalemonth1(){

        return salemonth1;

    }

    public void setRate1(double rate1){

        this.rate1=rate1;

    }

    public double getRate1(){

        return rate1;

    }

    public double getSalary(int month){

        if(this.getMonth() == month){

            System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1+100));

            return minsalary+salemonth1*rate1+100;

        }

        System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1));

        return minsalary+salemonth1*rate1;

    }

}

总类:

//某公司

public class test{

 public static void main(String[] args){

  Employee e1 = new Employee("小刘",9,0);

  e1.getSalary(6);

  SalariedEmployee s1 = new SalariedEmployee();

  s1.setName("小涛");

  s1.setSalary1(6300);

  s1.setMonth(6);

  s1.getMonth();

  s1.getSalary(6);

  HourlyEmployee h1 = new HourlyEmployee(192,36,0);

  h1.setName("小华");

  h1.setMonth(6);

  h1.getMonth();

  h1.getSalary(6);

  SalesEmployee ss1 = new SalesEmployee(26000,0.4);

  ss1.setName("陈一");

  ss1.setMonth(9);

  ss1.getMonth();

  ss1.getSalary(6);

  //System.out.println("该员工"+ss1.getName()+"的薪水为:"+ss1.getSalary(6));

  BasePlusSalesEmployee b1 =new BasePlusSalesEmployee(3000,9000,0.5);

  b1.setName("刘总");

  b1.setMonth(9);

  b1.getMonth();

  System.out.println("输出刘总的生日月份:"+b1.getMonth());

  b1.getSalary(9);

 }

}

猜你喜欢

转载自blog.csdn.net/m0_59186440/article/details/124723771
今日推荐