JAVA-1.9-homework

package Cola;

public abstract class ColaEmployee {
    String name;
    int birthmonth;
    
    public ColaEmployee() {
        
    }

    public ColaEmployee(String name, int birthmonth) {
        this.name = name;
        this.birthmonth = birthmonth;
    }

    abstract double getSalary(int month) ;
}
package Cola;

public class SalariedEmployee extends ColaEmployee{
    double salar;
    
    public SalariedEmployee() {
        
    }

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

    @Override
     double getSalary(int month) {
        if(month==birthmonth) {
            salar+=100;
        }
        return salar;
    }
}
package Cola;

public class HourlyEmployee extends ColaEmployee{
    double shourly;
    double hours;

    public HourlyEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public HourlyEmployee(String name, int birthmonth,double shourly,double hours) {
        super(name, birthmonth);
        // TODO Auto-generated constructor stub
        this.shourly=hours;
        this.hours=hours;
    }

    double getSalary(int month) {
        if(hours>160.0) {
            shourly=(160.0*shourly)+(hours-160.0)*(shourly*1.5);
        }else {
            shourly=hours*shourly;
        }
        if(month==birthmonth) {
            shourly+=100.0;
            return shourly;
        }else {
            return shourly;
        }
    }
}
package Cola;

public class SalesEmployee extends ColaEmployee{
    double smonthly;
    double rate;
    
     public SalesEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public SalesEmployee(String name, int birthmonth, double smonthly,double rate) {
        super(name, birthmonth);
        // TODO Auto-generated constructor stub
        this.smonthly=smonthly;
        this.rate=rate;
    }

    public double getSalary(int month) {
         smonthly=smonthly+smonthly*rate;
         if(month==birthmonth) {
             smonthly+=100;
             return smonthly;
         }else {
             return smonthly;
         }
     }
}
package Cola;

public class Company{
    public static void getSalary(ColaEmployee a,int month) {
        System.out.println(month+"月"+a.name+"员工"+"的月薪是"+a.getSalary(month)+"元。");
    }
}
package Cola;

public class TestCompany {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ColaEmployee [] b=new ColaEmployee[6];
        b[0]=new SalesEmployee("王伟", 4, 10000, 5);
        b[1]=new SalesEmployee("刘美",8,12000,5);
        b[2]=new SalariedEmployee("张钧", 11, 20000);
        b[3]=new SalariedEmployee("高晟", 2, 23000);
        b[4]=new HourlyEmployee("季澊", 9, 200, 168);
        b[5]=new HourlyEmployee("沈复",5,300,170);
        for (ColaEmployee a:b) {
            Company.getSalary(a,5);
        }
    }

}

 

posted on 2020-05-16 17:46  yunkuang  阅读(142)  评论(0编辑  收藏  举报