/*
*学生类,包括学生的基本信息
*/
public class studentTest2{
public static void main(String[] args){
int i;
for(i=0;i<10;i++) {
Student tom=new Student("Tom"+i);
if(i%2==0){
tom.setStudentSex("man");
}else{
tom.setStudentSex("female");
}
tom.setStudentAddress("America");
tom.setStudentNumber();
System.out.println(tom.toString());
}}}
class Student{
private String strName="";
private int number=0;
private String strSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
private Static int nextNumber=1;
public Student(String name){
strName=name;
}
public String getStudentName(){
return strName;
}
public int getStudentNumber(){
return number;
}
public void setStudentNumber(){
number=nextNumber;
nextNumber++;
}
public void setStudentSex(String sex){
strSex=sex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality(){
return strSpciality;
}
public void setStudentSpeciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public String toString (){
String information="student name="+strName+",student number="+number;
if(!strSex.equals(""))
information +=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",birthday="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}}