import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class Practice {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生成绩:姓名,语文成绩,数学成绩,英语成绩");
TreeSet<Studentp> ts = new TreeSet<>(new Comparator<Studentp>() {
@Override
public int compare(Studentp s1, Studentp s2) {
int num = s2.getSum() - s1.getSum();
return num == 0 ? 1: num;
}
});
while(ts.size() < 5){
String line = sc.nextLine();
String[] arr = line.split(",");
int chinese = Integer.parseInt(arr[1]);
int math = Integer.parseInt(arr[2]);
int english = Integer.parseInt(arr[3]);
ts.add(new Studentp(arr[0], chinese, math, english));
}
for (Studentp s : ts) {
System.out.println(s);
}
}
}
public class Studentp {
private String name;
private int chinese;
private int math;
private int english;
private int sum;
public Studentp(String name, int chinese, int math, int english) {
super();
this.name = name;
this.chinese = chinese;
this.math = math;
this.english = english;
this.sum = this.chinese + this.english + this.math;
}
public int getSum() {
return sum;
}
}
|