码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA-1.9-homework

时间:2020-05-16 18:36:51      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:void   +=   monthly   gen   package   bst   stc   http   rri   

技术图片

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);
        }
    }

}

技术图片

 

JAVA-1.9-homework

标签:void   +=   monthly   gen   package   bst   stc   http   rri   

原文地址:https://www.cnblogs.com/yunlan/p/12901469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!