-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
62 lines (49 loc) · 1.31 KB
/
Employee.java
File metadata and controls
62 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Entity;
import java.util.Date;
import java.util.GregorianCalendar;
//实现深clone
public class Employee implements Cloneable {
private String name;
private double salary;
private Date hireDay;
public Employee(String name,double salary){
this.name=name;
this.salary=salary;
this.hireDay=new Date();
}
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 Date getHireday() {
return hireDay;
}
//根据提供的值设置录用时间
public void setHireday(int year,int month,int day) {
Date newHireDay=new GregorianCalendar(year, month, day).getTime();
hireDay.setTime(newHireDay.getTime());
}
public void raiseSalary(double byPercent){
double raise=salary * byPercent/100;
salary+=raise;
}
//声明异常,只要方法中含有未实现cloneable接口的类,就抛出异常
public Employee clone() throws CloneNotSupportedException{
Employee clone=(Employee) super.clone();//Object.clone()
//可变子对象的克隆,,,String是不可变对象,因此不需要
clone.hireDay=(Date) hireDay.clone();
return clone;
}
@Override
public String toString() {
return "Employee [name=" + name + ", salary=" + salary + ", hireDay=" + hireDay + "]";
}
}