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


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


          網站導航:
           
          主站蜘蛛池模板: 成安县| 沂水县| 新泰市| 马公市| 克拉玛依市| 上杭县| 卢湾区| 泸州市| 遂溪县| 吴堡县| 佳木斯市| 吉隆县| 明光市| 郯城县| 雷波县| 轮台县| 定远县| 阜宁县| 永年县| 大田县| 太仆寺旗| 扶沟县| 长丰县| 灵武市| 福泉市| 凤凰县| 赣州市| 关岭| 潼南县| 商都县| 共和县| 崇仁县| 定西市| 海林市| 泸西县| 东乌珠穆沁旗| 衡东县| 营山县| 西藏| 克东县| 鄂州市|