public class kt01 {
public static void main(String[] args) throws IOException {
TreeSet<Student> ts = new TreeSet<Student>(new Comparator<Student>() {
@Override
public int compare(Student s1, Student s2) {
int num = s2.getsum()-s1.getsum();
int num1 = num ==0? s1.getChese()-s2.getChese():num;
int num2 = num1 ==0? s1.getMath()-s2.getMath():num1;
int num3 = num2 ==0? s1.getName().compareTo(s2.getName()):num2;
return num3;
}
});
for (int i = 0; i <5 ; i++) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入"+(i+1)+"个学生信息:");
System.out.println("姓名:");
String name = sc.nextLine();
System.out.println("语文成绩:");
int chese = sc.nextInt();
System.out.println("数学成绩:");
int math = sc.nextInt();
System.out.println("英语成绩:");
int engelith = sc.nextInt();
Student s = new Student();
s.setName(name);
s.setChese(chese);
s.setMath(math);
s.setEngelith(engelith);
ts.add(s);
}
BufferedWriter bw = new BufferedWriter(new FileWriter("itheima\\cj.txt"));
for (Student t : ts) {
StringBuilder sb = new StringBuilder();
sb.append(t.getName()).append(",").append(t.getChese()).append(",").append(t.getMath()).append(",").append(t.getEngelith()).append(",").append(t.getsum());
bw.write(sb.toString());
bw.newLine();
bw.flush();