import java.util.*;
public class CloneTest{
publci static void main (String[] args){
try{
Employee original=new Employee("John Q.public",50000);
original.setHireDay(2000,1,1);
Employee copy=original.clone();
copy.raiseSalary(10);
copy.setHireDay(2002,12,31);
System.out.println("original="+original);
}
catch (CloneNotSupportedExcepton e){
e.printStackTrace();
}
}
}
class Employee implements Cloneable{
public Employee (String n,double s){
name=n;
salary=s;
}
public Employee clone() throws CloneNotSupportedException{
Employee cloned=(Employee )super.clone();
cloned.hireDay=(Date)hireDay.clone();
return cloned;
}
publci void setHireDay(int year,int month,int day){
hireDay=new GregorianCalendar(year,month-1,day).getTime();
}
public void raiseSalary(double byPercent){
double raise =salary*byPercnet/100;
salary+=raise;
}
public String toString(){
return "Employee[name=]"+name+",salary+"+salary+",hireDay="+hireDay+"]";
}
private String name;
private double salary;
private Date hireDay;
}