StudentTest1.java
/** */
/**
* main方法单独设计,编译是不能通过
*/
public class StudentTest1 {
public static void main(String[] args)
{
String[] course={"计算机原理","编译方法","数据结构"};
Student one=new Student("Tom","20021024");
one.setStudentCourse(course);
}
}
/** */ /**
* 我们设计的学生基本类
*/
class Student
{
private String strName = "";//学生姓名
private String strNumber = "";//学号
private String strSex = "";//性别
private String strBirthday = "";//出生年月
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 void setStudentSex(String sex)
{
strSex = sex;
}
public String getStudentSex()
{
return strSex;
}
public String getStudentBirthday()
{
return strBirthday;
}
public void setStudentBirthday(String birthday)
{
strBirthday = birthday;
}
public String getStudentSpeciality()
{
return strSpeciality;
}
public void setStudentSpeciality(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 void setStudentCourse(final String[] strCourse){
class Course{
private int courseNumber=strCourse.length;
private void getCourse(){
for(int i=0;i<courseNumber;i++)
{System.out.println("\t"+strCourse[i]);
}
}
public void getDescription(){
System.out.println("学生:"+strName+" student number is :"+strNumber+"。一共选了"+courseNumber+"门课,分别是:");
getCourse();
}}
Course course=new Course();
course.getDescription();
}
}
* main方法单独设计,编译是不能通过
*/
public class StudentTest1 {
public static void main(String[] args)
{
String[] course={"计算机原理","编译方法","数据结构"};
Student one=new Student("Tom","20021024");
one.setStudentCourse(course);
}
}
/** */ /**
* 我们设计的学生基本类
*/
class Student
{
private String strName = "";//学生姓名
private String strNumber = "";//学号
private String strSex = "";//性别
private String strBirthday = "";//出生年月
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 void setStudentSex(String sex)
{
strSex = sex;
}
public String getStudentSex()
{
return strSex;
}
public String getStudentBirthday()
{
return strBirthday;
}
public void setStudentBirthday(String birthday)
{
strBirthday = birthday;
}
public String getStudentSpeciality()
{
return strSpeciality;
}
public void setStudentSpeciality(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 void setStudentCourse(final String[] strCourse){
class Course{
private int courseNumber=strCourse.length;
private void getCourse(){
for(int i=0;i<courseNumber;i++)
{System.out.println("\t"+strCourse[i]);
}
}
public void getDescription(){
System.out.println("学生:"+strName+" student number is :"+strNumber+"。一共选了"+courseNumber+"门课,分别是:");
getCourse();
}}
Course course=new Course();
course.getDescription();
}
}