public class Demo2 {
public static void main(String[] args) throws IOException {
//创建TreeSet集合
TreeSet<Student> set = new TreeSet<>(new Comparator<Student>() {
@Override
public int compare(Student s1, Student s2) {
int cmp1 = s2.getTotal() - s1.getTotal();
int cmp2 = cmp1 == 0 ? s2.getName().compareTo(s1.getName()) : cmp1;
return cmp2;
}
});
for (int i = 0;i < 3;i++){
//输入学生信息
System.out.println("请输入第"+(i+1)+"个学生信息:");
Scanner sc = new Scanner(System.in);
System.out.println("姓名:");
String name = sc.nextLine();
System.out.println("语文成绩:");
int chinese = sc.nextInt();
System.out.println("数学成绩:");
int math = sc.nextInt();
System.out.println("英语成绩:");
int english = sc.nextInt();
//创建学生对象并录入信息
Student s = new Student();
s.setName(name);
s.setChinese(chinese);
s.setMath(math);
s.setEnglish(english);