计算员工工资

1、员工总类

package LESSON6;
//员工总父类
public class Employee {
    private String name;
    private int month;
    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(this.month==month){
            return 100;
        }
        else{
            return 0;
        }        
    }
}

2、小时工类

package LESSON6;
public class HourlyEmployee extends Employee{
    private int hour;
    private double hsalary;
    public  HourlyEmployee(String name,int month,int hour,double hsalary){
        super(name,month);
        this.hour=hour;
        this.hsalary=hsalary;        
    }
    public double getSalary(int month){//当前月份
        if(hour<=160){
        return hsalary*hour+super.getSalary(month);
        }
        else{
            return (hsalary*160+(hour-160)*hsalary*1.5)+super.getSalary(month);
        }                
    }   
}

3、固定工资员工类

package LESSON6;
//拿固定工资的员工
public class SalariedEmployee extends Employee {
    public double msalary;//成员变量
    public SalariedEmployee(String name,int month,double msalary){//生日
        super(name,month);
        this.msalary=msalary;    
    }
    public double getSalary(int month){//当前月份
        return msalary+super.getSalary(month);                
    }            
}

4、销售人员类

package LESSON6;
public class SalesEmployee extends Employee{
    private double saleamonunt;
    private double rate;
public SalesEmployee(String name,int month,double saleamonunt,double rate){    
    super(name,month);
    this.saleamonunt=saleamonunt;
    this.rate=rate;
}
public double getSalary(int month){
    return saleamonunt*rate+super.getSalary(month);
}
}

5、有固定底薪的销售人员类

package LESSON6;
public class BasePlusSalesEmployee extends SalesEmployee{
    private double basesalary;  
    public BasePlusSalesEmployee(String name,int month,double basesalary,double saleamonunt,double rate){
        super(name,month,saleamonunt,rate);
        this.basesalary=basesalary;        
    }
    public double getSalary(int month){
        return basesalary+super.getSalary(month);
    }
}

6、测试类

package LESSON6;
import java.util.Scanner;
public class TestEmployee {
    public static void main(String[] args) {
        Employee se=new SalariedEmployee("张三",2,3000);
        System.out.println(se.getSalary(3));        
        Employee he=new HourlyEmployee("李四",3,180,10);
        System.out.println(he.getSalary(4));        
        Employee sse=new SalesEmployee("杨四",4,200000,0.02);
        System.out.println(sse.getSalary(5));          
        Employee bpse=new BasePlusSalesEmployee("王五",5,200000,0.01,3000);
        System.out.println(bpse.getSalary(6));        
        while(true){
        System.out.println("请输入要查询的月份,输入0结束");
        Scanner sc=new Scanner(System.in);
        int month=sc.nextInt();
        if(month==0){break;}
        else{        
        Employee emp[]={se,he,sse,bpse};
        System.out.println("姓名"+"\t"+"生日月份"+"\t"+"当前工资");
        for (int i = 0; i < emp.length; i++) {        System.out.println(emp[i].getName()+"\t"+emp[i].getMonth()+"\t"+emp[i].getSalary(month));
        }
        }
        }                
    }
}

7、运行结果

 

posted @ 2019-05-30 22:49  勤奋的园  阅读(348)  评论(0编辑  收藏  举报