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


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


          網站導航:
           
          主站蜘蛛池模板: 漳州市| 定西市| 抚顺市| 莱州市| 漠河县| 三亚市| 海兴县| 永昌县| 乌审旗| 长垣县| 淮阳县| 易门县| 中超| 丰台区| 巴林右旗| 林州市| 宁远县| 宝兴县| 梁平县| 叶城县| 城市| 平昌县| 上饶县| 邯郸县| 霍城县| 依兰县| 安新县| 罗甸县| 利辛县| 黄大仙区| 兴安盟| 昭通市| 三明市| 晴隆县| 怀柔区| 清水河县| 沙坪坝区| 双江| 多伦县| 依安县| 邵武市|