码迷,mamicode.com
首页 > 其他好文 > 详细

Employee类

时间:2018-08-16 00:54:31      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:[1]   setname   形式   nbsp   name   override   system   code   day   

 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类

标签:[1]   setname   形式   nbsp   name   override   system   code   day   

原文地址:https://www.cnblogs.com/xiaobo520/p/9484545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!