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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 阜平县| 商都县| 繁峙县| 文安县| 元朗区| 丽水市| 聂拉木县| 民县| 江阴市| 岑巩县| 卢龙县| 铜山县| 乌拉特后旗| 金山区| 疏附县| 罗山县| 土默特左旗| 普陀区| 巢湖市| 扬中市| 宁化县| 耿马| 石景山区| 德州市| 新郑市| 通许县| 客服| 盐边县| 漳浦县| 南木林县| 定远县| 仪陇县| 吉林省| 康保县| 韶山市| 崇礼县| 芦溪县| 临澧县| 疏附县| 高淳县| 余干县|