2 Star 0 Fork 0

BESTI.IS.JAVA2018/cxgg20165312

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TestScore.java 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
20165312cg 提交于 7年前 . 第十周课上测试
import java.util.*;
class StudentKey implements Comparable {
double d=0;
String s="";
StudentKey (double d) {
this.d=d;
}
StudentKey (String s) {
this.s=s;
}
public int compareTo(Object b) {
StudentKey st=(StudentKey)b;
if((this.d-st.d)==0)
return -1;
else
return (int)((this.d-st.d)*1000);
}
}
class StudentIF {
String name=null;
String number = null;
double math,english,computer,total,aver;
StudentIF(String s,String num, double m, double e, double f, double a,double b) {
name=s;
number = num;
math=m;
english=e;
computer=f;
total=a;
aver=b;
}
}
public class TestScore {
public static void main(String args[]) {
TreeMap<StudentKey, StudentIF> treemap = new TreeMap<StudentKey, StudentIF>();
String str[] = {"xuwen", "lijiaxin", "caoge", "zhangchenhui", "chenyouzhang"};
String number[] = {"20165310","20165311","20165312","20165313","20165314","20165315"};
double math[] = {89, 45, 78, 76, 60};
double english[] = {67, 68, 100, 30, 71};
double computer[] = {76, 40, 30, 90, 80};
double total[] = new double[5];
double aver[] = new double[5];
StudentIF student[] = new StudentIF[5];
for (int k = 0; k < student.length; k++) {
total[k] = math[k] + english[k] + computer[k];
aver[k] = total[k] / 3;
}
for (int k = 0; k < student.length; k++) {
student[k] = new StudentIF(str[k],number[k], math[k], english[k], computer[k], total[k], aver[k]);
}
StudentKey key[] = new StudentKey[5];
for (int k = 0; k < key.length; k++) {
key[k] = new StudentKey(student[k].total);
}
for (int k = 0; k < student.length; k++) {
treemap.put(key[k], student[k]);
}
int a = treemap.size();
System.out.println("一共有" + a + "个同学,按总成绩排序:");
Collection<StudentIF> collection = treemap.values();
Iterator<StudentIF> iter = collection.iterator();
while (iter.hasNext()) {
StudentIF stu = iter.next();
System.out.println("学号"+stu.number +"姓名 " + stu.name + " 总成绩 " + stu.total);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/BESTI-IS-JAVA-2018/cxgg20165312.git
git@gitee.com:BESTI-IS-JAVA-2018/cxgg20165312.git
BESTI-IS-JAVA-2018
cxgg20165312
cxgg20165312
master

搜索帮助