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 郭兴华 阅读(117) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: