java技術博客

          jsp博客
          數據加載中……
          Student.java
          /**
           * 我們設計的學生基本類
           
          */

          class Student
          {
              
          private String strName = "";//學生姓名
              private String strNumber = "";//學號
              private String strSex = "";//性別
              private String strBirthday = "";//出生年月
              private String strSpeciality = "";//專業
              private String strAddress = "";//地址
              private double totalScore;//學生的總分數
              
              
          public static void main(String[] args)
              
          {
                  String[] course 
          = {"計算機原理""編譯方法""數據結構"};
                  Student one 
          = new Student("Tom","20021024");
                  one.setStudentCourse(course);
              }

              
              
          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 double getStudentScore()
              
          {
                  
          return totalScore;
              }

              
              
          public void setStudentScore(double score)
              
          {
                  totalScore 
          = score;
              }

          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(String[] strCourse)
              
          {
                  
          new Course(strCourse);
              }

              
              
          //內部課程類
              private class Course
              
          {
                  
          private String[] strCourse;//學生課程的數組
                  private int courseNumber;
                  
                  
          public Course(String[] course)
                  
          {
                      strCourse 
          = course;    
                      courseNumber 
          = course.length;
                      getDescription();        
                  }

                  
                  
          private void getCourse()
                  
          {
                      
          for(int i = 0; i < courseNumber; i++)
                      
          {
                          System.out.print(
          "\t" + strCourse[i]);
                      }

                  }

                  
                  
          private void getDescription()
                  
          {
                      System.out.println(
          "學生: " + Student.this.strName + " 學號是:" +
                                         Student.
          this.strNumber + "。 一共選了" + 
                                          courseNumber 
          + "門課,分別是:");
                      getCourse();
                  }
                  
              }

          }

              

          posted on 2008-10-23 00:08 郭興華 閱讀(193) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 井研县| 全椒县| 汝州市| 万全县| 沛县| 清镇市| 海伦市| 郴州市| 彰化县| 赣州市| 乡城县| 宁德市| 汉川市| 通渭县| 读书| 石林| 昭苏县| 秀山| 庆阳市| 陆河县| 崇仁县| 北辰区| 手机| 昌宁县| 南部县| 全椒县| 宜宾市| 安泽县| 青铜峡市| 扎囊县| 儋州市| 延吉市| 山丹县| 津南区| 昭通市| 永平县| 辛集市| 涞源县| 满洲里市| 合江县| 白银市|