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 郭興華 閱讀(160) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 枞阳县| 竹溪县| 上犹县| 武定县| 天祝| 宣威市| 察隅县| 沈丘县| 江华| 岳阳市| 商水县| 拉孜县| 东山县| 禹城市| 广东省| 万州区| 宁远县| 迁安市| 巩留县| 金湖县| 临城县| 阿瓦提县| 鄂尔多斯市| 敦煌市| 开封县| 印江| 尼勒克县| 绿春县| 花垣县| 锡林郭勒盟| 巴彦淖尔市| 黎平县| 正阳县| 农安县| 沙湾县| 卢湾区| 广饶县| 郸城县| 扶绥县| 镇宁| 两当县|