package Week008;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java. util.Comparator;
import java.util. Scanner;
import java. util. TreeSet;
public class Test {
public static void main(String[] args) throws IOException {
TreeSet set= new TreeSet<>(new Comparator() {
public int compare (Student o1,Student o2){
int num=o1.getTotalScore()-o2.getTotalScore() ;
int num2=num==0?o1. getName ( ).compareTo(o2.getName()) : num;
return num2;
}
});
Scanner sc=new Scanner (System.in);
for (int i=1;i<=3;i++) {
Student student=new Student();
System.out.println("请输入第”+i+“个学生的姓名");
String name=sc.nextLine();
student.setHame(name);
System.out.println("请输入第"+i+"个学生的语文成绩");
int chineseScore=Integer.parseInt(sc.nextLine());
student.set (chineseScore);
System.out.println("请输入第"+i+"个学生的教学成绩");
int mathScore=Integer.parseInt(sc. nextLine());
student.setMathScore(mathScore);
System.out.println("请输入第"+i+"个学生的英语成绩");
int englishScore=Integer.parseInt(sc.nextLine());
student. setEnglishScore(englishScore);
//再把学对象存到集合中
set.add(student);
}
BufferedWriter out = new BufferedWriter(new FileWriter("studentScore. txt", true));
out.write("序号\t\t"+"姓名\t\t"+"语文成绩\t"+"数学成绩\t"+"英语成绩\t"+"总分");
out.newLine();
out. flush();
//遍历集合把数据存到文本文件中去
int index=1 ;
for (Student student : set){
out.write((index++)+"\t\t " +student.getName()+"\t\t"+student.getChineseScore()+"\t\t"+ student.getMathScore()+"\t\t"+student.getEnglishScore()+"\t\t" +student. getTotalScore());
out.newLine();out. flush();
out.close();
}
}
}