谁能帮我看看这道编程题

来源:百度知道 编辑:UC知道 时间:2024/06/15 04:02:33
有个表
学号 数学 语文 外语
01 70 80 90
02 68 37 18
03 100 98 37

用java编写出
他们的平均分并升序排列输出
写出jdoc

第一次看到这样的题,谁给我点思路
谢谢

用数组对象!关键是数组对象排序
public class Student{
private int id;
private int chinese;
private int math;
private int english;
private double avgCount;//类变量

public Student(int i,int c,int m,int e){//构造方法
id=i;
chinese=c;
math=m;
english=e;
avgCount=Math.round((c+m+e)/3*100)/100;
}
public static void main(String args[]){
Student student[]=new Student[3];//数组对象可以添加数组但必须实列化;现在是3个
student[0]=new Student(01,70,80,90);
student[1]=new Student(02,68,37,18);
student[2]=new Student(03,100,98,37);//这里可以修改数据但不能改变数据类型

for(int f=0;f<student.length;f++){//对数组排序
int tempIndex=f;
for(int s=f;s<student.length;s++){
if(student[tempIndex].avgCount<student[s].avgCount){
tempIndex=s;
}
}
Student tempStudent=student[tempIndex];
student[tempIndex]=student[f];
student[f]=tempStudent;
}
<