编辑代码

public class Employee { 
     public Employee(String name, int month) 
      { 
       this.name = name; 
        this.month = month; 
         } 
          
           public float get_Salary(int month) 
            { 
             //如果月份为员工生日月份,则增加100的 
              if (month == this.month) 
               { 
                return 100; 
                 } 
                  else 
                   { 
                    return 0; 
                     } 
                      
                       } 
                        
                         private String name; //员工姓名 
                          private int month; //员工的生日月份 
                           
                            public static void main(String args[]) 
                             { 
                              Employee a[] = new Employee[4]; 
                               
                                a[0] = new SalariedEmployee("A", 2, 1000); 
                                 a[1] = new HourlyEmployee("B", 3, 2000, 200); 
                                  a[2] = new SalesEmployee("C", 4, 50000, (float) 0.1); 
                                   a[3] = new BasedPlusSalesEmployee("D", 5, 50000, (float) 0.1, 1000); 
                                    
                                     System.out.println("A的工资为" + a[0].get_Salary(2)); 
                                      System.out.println("B的工资为" + a[1].get_Salary(2)); 
                                       System.out.println("C的工资为" + a[2].get_Salary(2)); 
                                        System.out.println("D的工资为" + a[3].get_Salary(2)); 
                                         
                                          } 
                                           } 
                                            
                                             //拿固定工资的员工 
                                              class SalariedEmployee extends Employee 
                                               { 
                                                public SalariedEmployee(String name, int month, float salary) 
                                                 { 
                                                  super(name, month); 
                                                   this.salary = salary; 
                                                    } 
                                                     
                                                      @Override 
                                                       public float get_Salary(int month) 
                                                        { 
                                                         return salary + super.get_Salary(month); 
                                                          } 
                                                           
                                                            private float salary; //月薪 
                                                             } 
                                                              
                                                               //按小时拿工资的员工 
                                                                class HourlyEmployee extends Employee 
                                                                 { 
                                                                  public HourlyEmployee(String name, int month, float salary, int hour) 
                                                                   { 
                                                                    super(name, month); 
                                                                     this.salary = salary; 
                                                                      this.hour = hour; 
                                                                       } 
                                                                        
                                                                         @Override 
                                                                          public float get_Salary(int month) 
                                                                           { 
                                                                            //大于160小时的情况 
                                                                             if (hour > 160) 
                                                                              { 
                                                                               return (float) (salary * 160 + (hour - 160) * salary * 1.5 
                                                                                + super.get_Salary(month)); 
                                                                                 } 
                                                                                  else 
                                                                                   { 
                                                                                    return salary * hour + super.get_Salary(month); 
                                                                                     } 
                                                                                      } 
                                                                                       
                                                                                        private float salary; //每小时工资 
                                                                                         private int hour; //每月工作的小时数 
                                                                                          } 
                                                                                           
                                                                                            //销售人员 
                                                                                             class SalesEmployee extends Employee 
                                                                                              { 
                                                                                               public SalesEmployee(String name, int month, float sale, float bonus) 
                                                                                                { 
                                                                                                 super(name, month); 
                                                                                                  this.sale = sale; 
                                                                                                   this.bonus = bonus; 
                                                                                                    } 
                                                                                                     
                                                                                                      @Override 
                                                                                                       public float get_Salary(int month) 
                                                                                                        { 
                                                                                                         return sale * bonus + super.get_Salary(month); 
                                                                                                          } 
                                                                                                           
                                                                                                            private float sale; //销售额 
                                                                                                             private float bonus; //提成率 
                                                                                                              } 
                                                                                                               
                                                                                                                //有固定底薪的销售人员 
                                                                                                                 class BasedPlusSalesEmployee extends SalesEmployee 
                                                                                                                  { 
                                                                                                                   public BasedPlusSalesEmployee(String name, int month, float sale, 
                                                                                                                    float bonus, float baseSalary) 
                                                                                                                     { 
                                                                                                                      super(name, month, sale, bonus); 
                                                                                                                       this.baseSalary = baseSalary; 
                                                                                                                        } 
                                                                                                                         
                                                                                                                          @Override 
                                                                                                                           public float get_Salary(int month) 
                                                                                                                            { 
                                                                                                                             return baseSalary + super.get_Salary(month); 
                                                                                                                              } 
                                                                                                                               
                                                                                                                                private float baseSalary; //底薪 
                                                                                                                                 }
                                                                                                                                 
}
}