import
java.util.Date;
import
java.util.GregorianCalendar;
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;
hireDay =
new
Date();
}
public
Employee clone()
throws
CloneNotSupportedException
{
Employee obj = (Employee)
super
.clone();
obj.hireDay = (Date)hireDay.clone();
return
obj;
}
public
void
setHireDay(
int
year,
int
month,
int
day)
{
Date newHireDay
=
new
GregorianCalendar(year,
month -
1
,
day)
.getTime();
hireDay.setTime(newHireDay.getTime());
}
public
void
raiseSalary(
double
byPercent)
{
double
raise = salary * byPercent /
100
;
salary += raise;
}
public
String toString()
{
return
(
"Employee[name="
+ name
+
", salary="
+ salary
+
", hireDay="
+ hireDay
+
"]"
);
}
public
static
void
main(String[] args)
{
try
{
Employee original
=
new
Employee(
"ABC X. YZ"
,
50000
);
original.setHireDay(
2000
,
1
,
1
);
Employee copy = original.clone();
copy.raiseSalary(
10
);
copy.setHireDay(
2002
,
12
,
31
);
System.out.println(
"original= "
+ original);
System.out.println(
"copy= "
+ copy);
}
catch
(CloneNotSupportedException e) {
e.printStackTrace();
}
}
}