數(shù)據(jù)加載中……
          StudentTest1.java

           

          /**
          * main方法單獨設(shè)計,編譯是不能通過
          */

          public class StudentTest1{
          public static void main(String[] args)
          {
          String[] course
          ={"計算機原理","編譯方法","數(shù)據(jù)結(jié)構(gòu)"};
          Student one
          =new Student("Tom","20021024");
          one.setStudentCourse(course);
          }

          }


          /**
           * 我們設(shè)計的學(xué)生基本類
           
          */

          class Student
          {
           
           
          private String strName = "";//學(xué)生姓名
           private String strNumber = "";//學(xué)號
           private String strSex = "";//性別
           private String strBirthday = "";//出生年月
           private String strSpeciality = "";//專業(yè)
           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 
          = "學(xué)生姓名=" + strName + ", 學(xué)號=" + strNumber;  
            
          if!strSex.equals("") )
             information 
          += ", 性別=" + strSex;
            
          if!strBirthday.equals(""))
             information 
          += ", 出生年月=" + strBirthday;
            
          if!strSpeciality.equals("") )
             information 
          += ", 專業(yè)=" + 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(
          "學(xué)生:"+strName+" student number is :"+strNumber+"。一共選了"+courseNumber+"門課,分別是:");
          getCourse();
          }
          }

          Course course
          =new Course();
          course.getDescription();
          }

          }

          posted on 2008-10-23 10:18 郭興華 閱讀(231) 評論(1)  編輯  收藏

          評論

          # re: StudentTest1.java 2008-10-23 11:12 楊愛友

          看不懂你的意思,代碼沒有縮進,看著很不習(xí)慣那。
            回復(fù)  更多評論    

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 新沂市| 景东| 沐川县| 哈尔滨市| 基隆市| 保山市| 漯河市| 拜城县| 娄烦县| 潜山县| 内乡县| 武山县| 萍乡市| 珠海市| 邵东县| 长寿区| 衡南县| 微山县| 灌云县| 寿阳县| 长顺县| 云安县| 嘉荫县| 太保市| 镇康县| 孝感市| 航空| 东源县| 德州市| 时尚| 老河口市| 吉林省| 黎川县| 水城县| 吉林市| 泰兴市| 安丘市| 武汉市| 北海市| 乐至县| 简阳市|