package demo; import java.time.LocalDate; public class Employee {
private String name;
private double salary;
private LocalDate hireDay; public Employee(String n,double s, int year,int month,int day) {
this.name = n;
this.salary = s;
this.hireDay = LocalDate.of(year,month,day);
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public double getSalary() {
return salary;
} public void setSalary(double salary) {
this.salary = salary;
} public LocalDate getHireDay() {
return hireDay;
} public void setHireDay(LocalDate hireDay) {
this.hireDay = hireDay;
} @Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", salary=" + salary +
", hireDay=" + hireDay +
'}';
} public void raiseSalary(double byPercent){ //增加薪水函数
double raise=salary*byPercent/100;
salary+=raise;
}
}
package demo; public class EmployeeTest {
public static void main(String[] args) {
Employee[] staff=new Employee[4]; staff[0]=new Employee("迪迦",50000,2001,11,11);
staff[1]=new Employee("戴拿",60000,2006,1,1);
staff[2]=new Employee("银河",40000,2106,6,7);
staff[3]=new Employee("罗布",53000,2018,7,1); for (Employee e:staff) { // 增加每个人5%的薪水
e.raiseSalary(5);
} for (Employee f:staff){ //以表格的形式把员工表输出出来
System.out.println(f.toString());
}
}
}