java技術博客

          jsp博客
          數據加載中……
          StaticInnerClass.java
          /**
          *靜態內部類的測試
          */
          import java.util.Vector;
          public class StaticInnerClass{
          public static void main(String[] args){
          Vector vec=new Vector();
          Student tom=new Student("Tom","20020410");
          Student jack=new Student("jack","20020411");
          Studentsmith=new Student("Smith ","20020412");
          Student rose=new Student("Rose","20020413");
          tom.setStudentScore(456);
          jack.setStudentScore(500);
          smith.setStudentScore(634);
          rose.setStudentScore(414);
          vec.add(tom);
          vec.add(jack);
          vec.add(smith);
          vec.add(rose);
          ArrayScore.PairScore pair=ArrayScore.minMax(vec);
          System.out.println("最高分數為:"+pair.getMaxScore());
          System.out.println("最低的分數為:")+pair.getMinScore();
          }}
          class ArrayScore{
          static class PairScore{
          private double maxScore;
          private double minScore;
          public PairScore(double max,double min){
          maxScore=max;
          minScore=min;
          }
          public double getMaxScore(){
          return maxScore;
          }
          public double getMinScore(){
          return minScore;
          }
          }
          public static PairScore minMax(Vector studentVec){
          double minScore=((Student)studentVec.get(0)).getStudentScore();
          double maxScore=((Student)studentVec.get(0)).getStudentScore();
          for(int i=1;i<studentVec.size();i++){
          double score=((Student)studentVec.get(i)).getStudentScore();
          if(minScore>score)
          minScore=score;
          if(maxScore<score)
          maxScore=score;
          }
          return new PairScore(maxScore,minScore);
          }
          }
          /**
          *我們設計的學生基本類
          */
          class Student{
          private String strName="";
          private Stirng strNumber="";
          private Stirng strSex="";
          private String strBirthday="";
          private String strSpeciality="";
          private String strAddress="";
          private double totalScore;//學生的總分數
          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 ="student name="+strName+"student number="+strNumber;
          if(!strSex.equals(""))
          information+=",sex="+strSex;
          if(!strBirthday.equals(""))
          information+=",Birthday="+strBirthday;
          if(!strSpeciality.equals(""))
          information+=",專業="+strSpeciality;
          if(!strAddress.equals(""))
          information+=",Address="+strAddress;
          return information;
          }



          }

          posted on 2008-10-23 09:40 郭興華 閱讀(123) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 屏山县| 龙海市| 陇川县| 丰原市| 比如县| 阜城县| 吉安县| 鹤山市| 麟游县| 绥江县| 元阳县| 甘洛县| 谷城县| 太湖县| 绥滨县| 嵊泗县| 五台县| 玛沁县| 惠来县| 梅州市| 盘锦市| 梁河县| 霍山县| 海淀区| 松潘县| 榆社县| 兴文县| 新巴尔虎右旗| 东山县| 华池县| 东乡县| 晴隆县| 前郭尔| 台州市| 修武县| 岐山县| 合水县| 屯门区| 西城区| 图片| 井陉县|