1 package demo;
 2 
 3 import java.time.LocalDate;
 4 
 5 public class Employee {
 6     private String name;
 7     private double salary;
 8     private LocalDate hireDay;
 9 
10     public Employee(String n,double s, int year,int month,int day) {
11         this.name = n;
12         this.salary = s;
13         this.hireDay = LocalDate.of(year,month,day);
14     }
15 
16     public String getName() {
17         return name;
18     }
19 
20     public void setName(String name) {
21         this.name = name;
22     }
23 
24     public double getSalary() {
25         return salary;
26     }
27 
28     public void setSalary(double salary) {
29         this.salary = salary;
30     }
31 
32     public LocalDate getHireDay() {
33         return hireDay;
34     }
35 
36     public void setHireDay(LocalDate hireDay) {
37         this.hireDay = hireDay;
38     }
39 
40     @Override
41     public String toString() {    
42         return "Employee{" +
43                 "name='" + name + '\'' +
44                 ", salary=" + salary +
45                 ", hireDay=" + hireDay +
46                 '}';
47     }
48 
49     public void raiseSalary(double byPercent){  //增加薪水函数
50         double raise=salary*byPercent/100;
51         salary+=raise;
52     }
53 }
 1 package demo;
 2 
 3 public class EmployeeTest {
 4     public static void main(String[] args) {
 5         Employee[] staff=new Employee[4];
 6 
 7         staff[0]=new Employee("迪迦",50000,2001,11,11);
 8         staff[1]=new Employee("戴拿",60000,2006,1,1);
 9         staff[2]=new Employee("银河",40000,2106,6,7);
10         staff[3]=new Employee("罗布",53000,2018,7,1);
11 
12         for (Employee e:staff) {    // 增加每个人5%的薪水
13             e.raiseSalary(5);
14         }
15 
16             for (Employee f:staff){    //以表格的形式把员工表输出出来
17                 System.out.println(f.toString());
18             }
19         }
20 }

 

posted on 2018-08-15 22:49  蓝绿绿  阅读(335)  评论(0编辑  收藏  举报