java技术博客

jsp博客
数据加载中……
StudentTest.java
/*
*学生类,包括学生类的基本信息
*/
public class StudentTest{
public static void main(String[] args)
{
Student tom=new Student("Tom","20020410");
tom.setStudentSex("man");
tom.setStudentAddress("America");
System.out.println(tom.toString());
}
}
class Student{
private String strName=";
private String strNumber="";
private String strSex="";
private String strSpeciality="";
private String strAddress="";
public Student(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String getStudentSex(){
return strStudentSex;
}
public String setStudentSex(String sex)
{
strSex=sex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality()
{
return strSpeciality;
}
public void setStudentSpeciality(){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address){
strAddress=address;
}
public String toString(){
String information ="student name="+strName+",student number ="+strNumber;
if(!strSex.equals(""))
information+=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",birthday ="+strBirthday;
if(!strAddress.equals(""))
information+=",address="+strAddress;
return information;
}

}

}

posted on 2008-10-21 18:16 郭兴华 阅读(210) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: