12.教师管理系统(未解决:Date数据输出错误;问题在最长的一行)

作者在 2016-08-23 23:07:49 发布以下内容
12.教师管理系统(未解决:Date数据输出错误;问题在最长的一行)
package xiti;
class Date{
private int year;
int month;
private int day;
public Date(int y,int m,int d){
this.year=y;
this.month=m;
this.day=d;
}
Date(){
year=2016;
month=6;
day=16;
}
public int getyear(){
return year;
}
public int getmonth(){
return month;
}
public int getday(){
return day;
}
public void setDate(Date da){
year=da.getyear();
month=da.getmonth();
day=da.getday();
}
}
public class Teacher {
protected String name;
protected boolean sex;
protected Date birth;
protected String salaryID;
protected String depart;
protected String posit;

public String getname(){
return name;
}
public boolean getsex(){
return sex;
}
public Date getbirth(){
return birth;
}
public String getsalaryID(){
return salaryID;
}
public String getdepart(){
return depart;
}
public String getposit(){
return posit;
}
/*protected String name;
protected boolean sex;
protected Date birth;
protected String salaryID;
protected String depart;
protected String posit;
*/
public void setname(String name){
this.name=name;
}
public void setsex(boolean sex){
this.sex=sex;
}
public void setbirth(Date da){
this.birth=da;
}
public void setsalaryID(String sa){
this.salaryID=sa;
}
public void setdepart(String de){
this.depart=de;
}
public void setposit(String po){
this.posit=po;
}
public Teacher(String name,boolean sex,Date birth,String salartID,String depart,String posit){
this.name=name;
this.sex=sex;
this.birth=birth;
this.salaryID=salaryID;
this.depart=depart;
this.posit=posit;

}
public Teacher(){
name="virtual man";
sex=false;
birth=new Date();
salaryID="007";
depart="keep secret";
posit="unknown";


}
public void print(){
System.out.println(this.getname());
System.out.print("the sex is : ");
if(this.getsex()==true)
{System.out.println("male");}
else {System.out.println("female");}
System.out.print("the birth is: ");
System.out.println(this.getbirth().getyear()+this.getbirth().getmonth()+this.getbirth().getday());//注意这里,可能有错              在这里怎么调用本文件创建的Date类的数据
System.out.print("the salaryID is: ");//在这里怎么调用本文件创建的Date类的数据
System.out.println(getsalaryID());
System.out.print("the depart is :");
System.out.println(this.getdepart());
System.out.print("the pasit is :");
System.out.println(this.getposit());

}
public static void main(String[] args) {
Date d1=new Date(1993,12,16);
Date d2=new Date(1994,12,16);
Date d3=new Date(1995,12,16);
Date d4=new Date(1996,12,16);
Date d5=new Date(1997,12,16);
//Teacher(String name,boolean sex,Date birth,String salartID,String depart,String posit)
Teacher t1=new Teacher("zhangsan",false,d1,"001","cs","Prefessor");
researchTeacher t2=new researchTeacher("zhangsan",false,d2,"002","cs","Prefessor","sotftware");
labTeacher t3=new labTeacher("zhangsan",false,d3,"003","cs","Prefessor","");
libTeacher t4=new libTeacher("zhangsan",false,d4,"004","cs","Prefessor","");
adminTeacher t5=new adminTeacher("zhangsan",false,d5,"005","cs","Prefessor","");
System.out.println("-------------------------------------------");
t1.print();
System.out.println("-------------------------------------------");
t2.print();
System.out.println("-------------------------------------------");
t3.print();
System.out.println("-------------------------------------------");
t4.print();
System.out.println("-------------------------------------------");
t5.print();
System.out.println("-------------------------------------------");


}


}
class researchTeacher extends Teacher{
private String resField;
public researchTeacher(String name,boolean sex,Date birth,String salaryid,String depart,String posit,String resField){
this.name=name;
this.sex=sex;
this.salaryID=salaryid;
this.depart=depart;
this.posit=posit;
this.resField=resField;
}


String getresField(){
return resField;
}
public void setresField(String res){
resField=res;
}
public void print(){
System.out.println(this.getname());
System.out.print("the sex is : ");
if(this.getsex()==true)
{System.out.println("male");}
else {System.out.println("female");}
System.out.print("the birth is: ");
System.out.println(this.getbirth().getyear()+this.getbirth().getmonth()+this.getbirth().getday());//注意这里,可能有错
System.out.print("the salaryID is: ");
System.out.println(getsalaryID());
System.out.print("the depart is :");
System.out.println(this.getdepart());
System.out.print("the pasit is :");
System.out.println(this.getposit());
System.out.print("the resField is :");
System.out.println(this.getresField());
}
}
class labTeacher extends Teacher{
private String labName;
public labTeacher(String name,boolean sex,Date birth,String salaryid,String depart,String posit,String labname){
this.name=name;
this.sex=sex;
this.salaryID=salaryid;
this.depart=depart;
this.posit=posit;
this.labName=labname;
}
String getlabName(){
return labName;
}
public void setlabName(String name){
this.labName=name;
}
public void print(){
System.out.println(this.getname());
System.out.print("the sex is : ");
if(this.getsex()==true)
{System.out.println("male");}
else {System.out.println("female");}
System.out.print("the birth is: ");
System.out.println(this.getbirth().getyear()+this.getbirth().getmonth()+this.getbirth().getday());//注意这里,可能有错
System.out.print("the salaryID is: ");
System.out.println(getsalaryID());
System.out.print("the depart is :");
System.out.println(this.getdepart());
System.out.print("the pasit is :");
System.out.println(this.getposit());
System.out.print("the labName is :");
System.out.println(this.getlabName());
}
}
class libTeacher extends Teacher{
private String libName;
public libTeacher(String name,boolean sex,Date birth,String salaryid,String depart,String posit,String libname){
this.name=name;
this.sex=sex;
this.salaryID=salaryid;
this.depart=depart;
this.posit=posit;
this.libName=libname;
}
String getlibName(){
return libName;
}
public void setlibName(String name){
this.libName=name;
}
public void print(){
System.out.println(this.getname());
System.out.print("the sex is : ");
if(this.getsex()==true)
{System.out.println("male");}
else {System.out.println("female");}
System.out.print("the birth is: ");
System.out.println(this.getbirth().getyear()+this.getbirth().getmonth()+this.getbirth().getday());System.out.print("the salaryID is: ");
System.out.println(getsalaryID());
System.out.print("the depart is :");
System.out.println(this.getdepart());
System.out.print("the pasit is :");
System.out.println(this.getposit());
System.out.print("the libName is :");
System.out.println(this.getlibName());
}
}
class adminTeacher extends Teacher{
private String managePos;
public adminTeacher(String name,boolean sex,Date birth,String salaryid,String depart,String posit,String managePos){
this.name=name;
this.sex=sex;
this.salaryID=salaryid;
this.depart=depart;
this.posit=posit;
this.managePos=managePos;
}
String getmanagePos(){
return managePos;
}
public void setmanagePos(String name){
this.managePos=name;
}
public void print(){
System.out.println(this.getname());
System.out.print("the sex is : ");
if(this.getsex()==true)
{System.out.println("male");}
else {System.out.println("female");}
System.out.print("the birth is: ");
System.out.println(this.getbirth().getyear()+this.getbirth().getmonth()+this.getbirth().getday());//注意这里,可能有错
System.out.print("the salaryID is: ");
System.out.println(getsalaryID());
System.out.print("the depart is :");
System.out.println(this.getdepart());
System.out.print("the pasit is :");
System.out.println(this.getposit());
System.out.print("the managePos is :");
System.out.println(this.getmanagePos());
}
}




输出结果为:




-------------------------------------------
zhangsan
the sex is : female
the birth is: 2021
the salaryID is: null
the depart is :cs
the pasit is :Prefessor
-------------------------------------------
zhangsan
the sex is : female
the birth is: 2038
the salaryID is: 002
the depart is :cs
the pasit is :Prefessor
the resField is :sotftware
-------------------------------------------
zhangsan
the sex is : female
the birth is: 2038
the salaryID is: 003
the depart is :cs
the pasit is :Prefessor
the labName is :
-------------------------------------------
zhangsan
the sex is : female
the birth is: 2038
the salaryID is: 004
the depart is :cs
the pasit is :Prefessor
the libName is :
-------------------------------------------
zhangsan
the sex is : female
the birth is: 2038
the salaryID is: 005
the depart is :cs
the pasit is :Prefessor
the managePos is :
-------------------------------------------


















代码-中级 | 阅读 2963 次
文章评论,共0条
游客请输入验证码
文章归档
最新评论