第十五周作业

public class ColaEmployee {
protected String name;
protected int month;
 
 public ColaEmployee() {
super();

       }
    
        public ColaEmployee(String name, int month) {
            super();
            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) {
             return 0;
     
        }
    }
package dmk;

public class SalariedEmployee extends ColaEmployee{
    double monthSalary;
 
     public SalariedEmployee() {
         super();
 
    }

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

   public double getSalary(int month) {
         if (super.getMonth() == month) {
            return monthSalary + 100;
        } else {
             return monthSalary;
        }
     }
}
public class HourlyEmpiloyee extends ColaEmployee{

int hS;
int hN;
    
            public HourlyEmpiloyee() {
                super();
    
            }
        
           public HourlyEmpiloyee(String name, int month, int hS, int hN) {
                super(name, month);
                 this.hS = hS;
                this.hN = hN;
            }
        
           public double getSalary(int month) {
               if (super.getMonth() > month) {
                   if (hN> 160) {
                       return hS * 160 + hS * (hN - 160) * 1.5 + 100;
                    } else {
                         return hS * hN + 100;
        
                     }
                } else {
                      if (hN > 160) {
                        return hS * 160 + hS * (hN - 160) * 1.5;
                    } else {
                         return hS * hN;
        
                    }
                }
           }}
package dmk;

public class SalesEmployee extends ColaEmployee{
int monthSales;
double tich;

  public SalesEmployee() {
      super();

   }

  public SalesEmployee(String name, int month, int monthSales, double ticheng) {
       super(name, month);
        this.monthSales = monthSales;
        this.tich = ticheng;
    }
 
    public double getSalary(int month) {
        if (super.getMonth() == month) {
            return monthSales * tich + 100;
         } else {
             return monthSales * tich;
         }
    }
 
}
package dmk;

public class Company {

    public void getSalary(ColaEmployee a, int month) {
              System.out.println(a.name + "在" + month + "月的工资为" + a.getSalary(month));
          }
       
       }

package dmk;

public class test {


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ColaEmployee[] c = { 
                new SalariedEmployee("DMK", 5, 2356), 
                new HourlyEmpiloyee("XSC", 3, 8, 450),
                new SalesEmployee("DAW", 4, 48763, 0.5) 
                };
        for (int i = 0; i < c.length; i++) {
            new Company().getSalary(c[i], 12);
        }

    }

}

 

 

posted @ 2021-06-18 15:09  董梦坤  阅读(45)  评论(0编辑  收藏  举报