@Override
public int compare(Student s1, Student s2) {
int num = s2.getSum() - s1.getSum();
return num == 0 ? 1 : num;
}
});
//4,录入五个学生,所以以集合中的学生个数为判断条件,如果size是小于5就进行存储
while(ts.size() < 5) {
//5,将录入的字符串切割,用逗号切割,会返回一个字符串数组,将字符串数组中从二个元素转换成int数,
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]);
//6,将转换后的结果封装成Student对象,将Student添加到TreeSet集合中
ts.add(new Student(arr[0], chinese, math, english));
}
//7,遍历TreeSet集合打印每一个Student对象
System.out.println("排序后的学生信息:");
for (Student s : ts) {
System.out.println(s);
}
}