public class Student {

private String no;

private String name;

private double score;

private int rank;


public Student(String no, String name, double score) {

this.no = no;

this.name = name;

this.score = score;

}


public String getNo() {

return no;

}


public void setNo(String no) {

this.no = no;

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public double getScore() {

return score;

}


public void setScore(double score) {

this.score = score;

}


public int getRank() {

return rank;

}


public void setRank(int rank) {

this.rank = rank;

}


@Override

public String toString() {

return "Student [no=" + no + ", name=" + name + ", score=" + score

+ ", rank=" + rank + "]";

}


}

public class Test {

public static void main(String[] args) {

List<Student> students = new ArrayList<Student>();

students.add(new Student("stu01", "张三", 80));

students.add(new Student("stu02", "钱六", 80));

students.add(new Student("stu03", "王五", 60));

students.add(new Student("stu04", "李四", 90));

for (Student stu : students) {

int i = sumCount(stu, students);// 算排名

stu.setRank(i);

}

for (Student student : students) {

System.out.println(student);

}

}


private static int sumCount(Student stu, List<Student> students) {

int i = 1;

for (Student student : students) {

double temp = student.getScore();

if (temp > stu.getScore()) {

i++;

}

}

return i;

}

}