简历代码初步实现
简历
public class Resume {
private String name;
private String age;
private String sex;
private String timeArea;
private String company;
public Resume(String name) {
this.name=name;
}
//设置个人信息
public void SetPersonalInfo(String sex,String age) {
this.sex=sex;
this.age=age;
}
//设置工作经历
public void SetWorkExperience(String timeArea,String company) {
this.timeArea=timeArea;
this.company=company;
}
//显示
public void DIsplay() {
System.out.println(this.getName()+" "+this.getSex()+" "+this.getAge());
System.out.println("工作经历 "+this.getTimeArea()+" "+this.getCompany());
}
//省略get ,set方法
}
**客户端调用代码**
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Resume a=new Resume("大鸟");
a.SetPersonalInfo("男","29");
a.SetWorkExperience("1998-2000", "xx公司");
Resume b=new Resume("大鸟");
b.SetPersonalInfo("男","29");
b.SetWorkExperience("1998-2000", "xx公司");
Resume c=new Resume("大鸟");
c.SetPersonalInfo("男","29");
c.SetWorkExperience("1998-2000", "xx公司");
a.DIsplay();
b.DIsplay();
c.DIsplay();
}
}
b、c可以更改为{
Resume b=a;
,。。。
}
结果
简历的原型实现
简历类
package 简历类;
public class Resume2 implements Cloneable{
private String name;
private String age;
private String sex;
private String timeArea;
private String company;
public Resume2(String name) {
this.name=name;
}
//设置个人信息
public void SetPersonalInfo(String sex,String age) {
this.sex=sex;
this.age=age;
}
//设置工作经历
public void SetWorkExperience(String timeArea,String company) {
this.timeArea=timeArea;
this.company=company;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getTimeArea() {
return timeArea;
}
public void setTimeArea(String timeArea) {
this.timeArea = timeArea;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
//显示
public void DIsplay() {
System.out.println(this.getName()+" "+this.getSex()+" "+this.getAge());
System.out.println("工作经历 "+this.getTimeArea()+" "+this.getCompany());
}
public Object Clone() {
try {
return (Object)this.clone();
} catch (CloneNotSupportedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return null;
}
}
客户端
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Resume2 a=new Resume2("大鸟");
a.SetPersonalInfo("男","29");
a.SetWorkExperience("1998-2000", "xx公司");
Resume2 b=(Resume2) a.Clone();
b.SetWorkExperience("1998-2006", "yy公司");
Resume2 c=(Resume2) a.Clone();
c.SetPersonalInfo("男","24");
a.DIsplay();
b.DIsplay();
c.DIsplay();
}
}
结果
浅复制
工作经历类
package 简历类;
public class WorkExperience {
private String workDate;
private String company;
public String getWorkDate() {
return workDate;
}
public void setWorkDate(String workDate) {
this.workDate = workDate;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
}
简历类
package 简历类;
public class Resume3 implements Cloneable{
private String name;
private String age;
private String sex;
private WorkExperience work;
public Resume3(String name) {
this.name=name;
work=new WorkExperience();
}
//设置个人信息
public void SetPersonalInfo(String sex,String age) {
this.sex=sex;
this.age=age;
}
public void SetWorkExperience(String workDate,String company) {
work.setWorkDate(workDate);
work.setCompany(company);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
//显示
public void DIsplay() {
System.out.println(this.getName()+" "+this.getSex()+" "+this.getAge());
System.out.println("工作经历 "+work.getWorkDate()+" "+work.getCompany());
}
public Object Clone() {
try {
return (Object)super.clone();
} catch (CloneNotSupportedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return null;
}
}
客户端
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Resume3 a=new Resume3("大鸟");
a.SetPersonalInfo("男","29");
a.SetWorkExperience("1998-2000", "xx公司");
Resume3 b=(Resume3) a.Clone();
b.SetWorkExperience("1998-2006", "yy公司");
Resume3 c=(Resume3) a.Clone();
c.SetPersonalInfo("男","24");
c.SetWorkExperience("1998-2003", "zz公司");
a.DIsplay();
b.DIsplay();
c.DIsplay();
}
}
结果
简历的深复制实现
工作经历类
package 简历类;
public class WorkExperience2 implements Cloneable{
private String workDate;
private String company;
public String getWorkDate() {
return workDate;
}
public void setWorkDate(String workDate) {
this.workDate = workDate;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Object Clone() {
try {
return (Object)this.clone();
} catch (CloneNotSupportedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return company;
}
}
简历类
package 简历类;
public class Resume4 implements Cloneable{
private String name;
private String age;
private String sex;
private WorkExperience2 work;
public Resume4(String name) {
this.name=name;
work=new WorkExperience2();
}
private Resume4(WorkExperience2 work) {
this.work=(WorkExperience2)work.Clone();
}
//设置个人信息
public void SetPersonalInfo(String sex,String age) {
this.sex=sex;
this.age=age;
}
//设置工作经历
public void SetWorkExperience2(String workDate,String company) {
work.setWorkDate(workDate);
work.setCompany(company);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
//显示
public void DIsplay() {
System.out.println(this.getName()+" "+this.getSex()+" "+this.getAge());
System.out.println("工作经历 "+work.getWorkDate()+" "+work.getCompany());
}
public Object Clone() {
Resume4 obj=new Resume4(this.work);
obj.name=this.name;
obj.sex=this.sex;
obj.age=this.age;
return obj;
}
}
客户端
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Resume4 a=new Resume4("大鸟");
a.SetPersonalInfo("男","29");
a.SetWorkExperience2("1998-2000", "xx公司");
Resume4 b=(Resume4) a.Clone();
b.SetWorkExperience2("1998-2006", "yy公司");
Resume4 c=(Resume4) a.Clone();
c.SetPersonalInfo("男","24");
c.SetWorkExperience2("1998-2003", "zz公司");
a.DIsplay();
b.DIsplay();
c.DIsplay();
}
}
结果、