📄 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");
Student smith = 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 String strNumber = "";//学号
private String 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 = "学生姓名=" + strName + ", 学号=" + strNumber;
if( !strSex.equals("") )
information += ", 性别=" + strSex;
if( !strBirthday.equals(""))
information += ", 出生年月=" + strBirthday;
if( !strSpeciality.equals("") )
information += ", 专业=" + strSpeciality;
if( !strAddress.equals("") )
information += ", 籍贯=" + strAddress;
return information;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -