StudentTest3.java
public class StudentTest3{
public static void main(String[] args){
Student tom=new Student("Tom","20020410");
tom.setStudentSex("man");
tom.setSutdentAddress("America");
System.out.println(tom.toString());
}
}
class Student{
private String strName="";
private String strNumber="";
private String sexSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
public static void main(String[] args){
Student aStudent=new Student("沙和尚","19990000");
aStudent.setStudentAddress("通天河");
System.out.println(aStudent.toString());
}
public Student (String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public void setStudentSex(String sex){
strSex=sex;
}
public String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentSpciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address) {
strAddress=address;
}
public String toString(){
String information="学生姓名="+strName+",学号="+strNumber;
if(!strSex.equals("")){
information+=",性别="+strSex;
if(!strBirthday.equals(""))
information+=", 出生年月="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}
}
}
public static void main(String[] args){
Student tom=new Student("Tom","20020410");
tom.setStudentSex("man");
tom.setSutdentAddress("America");
System.out.println(tom.toString());
}
}
class Student{
private String strName="";
private String strNumber="";
private String sexSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
public static void main(String[] args){
Student aStudent=new Student("沙和尚","19990000");
aStudent.setStudentAddress("通天河");
System.out.println(aStudent.toString());
}
public Student (String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public void setStudentSex(String sex){
strSex=sex;
}
public String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentSpciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address) {
strAddress=address;
}
public String toString(){
String information="学生姓名="+strName+",学号="+strNumber;
if(!strSex.equals("")){
information+=",性别="+strSex;
if(!strBirthday.equals(""))
information+=", 出生年月="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}
}
}