Employee类

Posted xiaobo520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Employee类相关的知识,希望对你有一定的参考价值。

 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 }

 


以上是关于Employee类的主要内容,如果未能解决你的问题,请参考以下文章

无法解码 Employee 类对象的键(NS.object.0);该类可以在源代码或未链接的库中定义

代码阅读

未来不返回任何东西

继承-从Employee类创建一个Class Employee雇员并进行测试

如何遍历类中的 SortedList

如何通过单击片段内的线性布局从片段类开始新活动?下面是我的代码,但这不起作用