帮忙找一下问题所在!
/*
希望在学生毕业的时候统计出学生在校期间考试成绩的排名,
写一个Student类,其中用集合来管理每个学生的各个科目的考试成绩,
将多个Student对象放在集合中,打印出学生的总分以及排名
*/
import java.util.*;
public class SortStudent{
public static void main(String[] args){
List <Student> l=new ArrayList <Student> ();
l.add(new Student( "hlonger ",30));
l.add(new Student( "bluelaster ",19));
l.add(new Student( "mk ",24));
Collections.sort(l);
print(l);
}
public static void print(List <Student> li){
Iterator <Student> it=li.iterator();
for(Student s:li)
System.out.println(s);
}
}
class Student implements Comparable <Student> {
private String name;
private int age;
Random rd=new Random();
public Student(){}
public Student(String name,int age){
this.name=name;
this.age=age;
}
List <Kecheng> li=new ArrayList <Kecheng> ();
li.add(new Course( "英语 ",rd.nextInt(100)));
li.add(new Course( "物理 ",rd.nextInt(100)));
li.add(new Course( "化学 ",rd.nextInt(100)));
li.add(new Course( "语文 ",rd.nextInt(100)));
public String toString(){
return "Student: "+name+ " Age: "+age;
}
public double getSumOfScore(List <Kecheng> li){
double sum=0.0;
for(int i=0;i <li.size();i++)
sum+=li[i].getScore();
return sum;
}
public int compareTo(Student s){
return (int)(this.getSumOfScore(this.li)-s.getSumOfScore(s.li));
}
}
class Kecheng{
private String cname;
private double score;
public Kecheng(){}
public Kecheng(String cname,double score){
this.cname=cname;
this.score=score;
}
public String getCname(){
return cname;