//设置分数
public boolean setScore(double[] score) {
//判断分数是否合法
boolean ck=checkScore(score);
//合法,返回true,并设置score
if (ck){
this.score = score;
return true;
}else{
return false;
}
}
//判断分数是否合法
public boolean checkScore(double[] score){
for (int i=0;i //数据不合法,直接返回
if (score[i]<0||score[i]>100){
return false;
}
}
return true;
}
public double[] max_min(){
//用于存放最大值和最小值
double [] max_min=new double[2];
//声明最大最小值,并附初始值
double max=score[0];
double min=score[0];
for (int i=0;i if(score[i]>max){
max=score[i];
}
if(score[i] min=score[i];
}
}
max_min[0]=max;
max_min[1]=min;
return max_min;
}
//main函数赋值
double[]score=new double[]{20,30,40,50,60};
Student st=new Student("百度知道","001");
boolean bl= st.setScore(score);
if (bl){
System.out.println("设置成功");
}else{
System.out.println("设置失败,有异常数据!");
}