java技術博客

          jsp博客
          數據加載中……
          StudentTest2.java
          /*
          *學生類,包括學生的基本信息
          */
          public class studentTest2{
          public static void main(String[] args){
          int i;
          for(i=0;i<10;i++) {
          Student tom=new Student("Tom"+i);
          if(i%2==0){
          tom.setStudentSex("man");
          }else{
          tom.setStudentSex("female");
          }
          tom.setStudentAddress("America");
          tom.setStudentNumber();
          System.out.println(tom.toString());
          }}}
          class Student{
          private String strName="";
          private int number=0;
          private String strSex="";
          private String strBirthday="";
          private String strSpeciality="";
          private String strAddress="";
          private Static int nextNumber=1;
          public Student(String name){
          strName=name;
          }
          public String getStudentName(){
          return strName;
          }
          public int getStudentNumber(){
          return number;
          }
          public void setStudentNumber(){
          number=nextNumber;
          nextNumber++;
          }
          public void setStudentSex(String sex){
          strSex=sex;
          }
          public String getStudentBirthday(){
          return strBirthday;
          }
          public void setStudentBirthday(String birthday){
          strBirthday=birthday;
          }
          public String getStudentSpeciality(){
          return strSpciality;
          }
          public void setStudentSpeciality(String speciality){
          strSpeciality=speciality;
          }
          public String getStudentAddress(){
          return strAddress;
          }
          public String toString (){
          String information="student name="+strName+",student number="+number;
          if(!strSex.equals(""))
          information +=",sex="+strSex;
          if(!strBirthday.equals(""))
          information+=",birthday="+strBirthday;
          if(!strSpeciality.equals(""))
          information+=",專業="+strSpeciality;
          if(!strAddress.equals(""))
          information+=",籍貫="+strAddress;
          return information;
          }}

          posted on 2008-10-21 20:25 郭興華 閱讀(158) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 山阳县| 龙海市| 信宜市| 滁州市| 长治市| 长寿区| 武定县| 陵水| 临泽县| 辽中县| 河间市| 鹰潭市| 江西省| 新竹县| 绍兴市| 海安县| 从化市| 皋兰县| 松潘县| 娄底市| 沾化县| 柘荣县| 鸡东县| 固安县| 文昌市| 宜章县| 金山区| 徐水县| 永善县| 洛宁县| 收藏| 安阳市| 银川市| 东平县| 独山县| 准格尔旗| 巴林右旗| 仙居县| 鲁山县| 井冈山市| 文安县|