/** 3, there are five students, each student has 3 courses (Chinese, maths, English) scores, * Write a program to receive information from the keyboard input students, the input format is: name,30,30,30 (name, three class results), * The input student information is then written to a file named "Stu.txt" in the order of the total score from highest to lowest. * Requirements: Stu.txt file format to be more intuitive, open this file, you can clearly see the student's information **/ImportJava.io.*;ImportJava.util.*; Public classTest3 { Public Static voidMain (string[] args)throwsexception{//number of incoming studentsStudent (5); } //Keyboard entry students, save to Stu.txt method Public Static voidStudent (intNumberthrowsexception{//Create scanner object accept input from consoleScanner in=NewScanner (system.in); //because students may appear the same name and total score, in order to ensure that students do not lose, set up a list containerList<student> list=NewArraylist<>(); //cycle into the set of students, arrange the order .SYSTEM.OUT.PRINTLN ("Input format: Name, language, Math, English (, number is lowercase state)"); for(intx=1;x<=number;x++) {System.out.println ("Please enter the information for" +x+ "student"); String[] s=in.nextline (). Split (","); intA=integer.parseint (s[1]); intB=integer.parseint (s[2]); intC=integer.parseint (s[3]); Student Stu=NewStudent (s[0],a,b,c); List.add (Stu); } //sorting from high to low with comparatorsCollections.sort (list,NewStucompare ()); //define output stream output to Stu.txtBufferedWriter bufw=NewBufferedWriter (NewFileWriter ("Stu.txt")); for(Student stu:list) {bufw.write (Stu.getstu ()); Bufw.newline (); Bufw.flush (); } //Close ResourceIn.close (); Bufw.close (); }}//Student Objectsclassstudent{PrivateString name; Private intA, B, c,sum; //Student object establishment need to pass in name and 3 course gradeStudent (String name,intAintBintc) { This. name=name; This. a=A; This. b=b; This. c=C; Sum=a+b+C; } Public intgetsum () {returnsum; } //output A string that conforms to the format PublicString Getstu () {returnname+ "Mathematics:" +a+ "Chinese:" +b+ "English:" +c+ "score:" +sum; }}//define comparators, sorted by total scoreclassStucompareImplementsComparator<student>{ Public intCompare (Student s1,student s2) {intA=NewInteger (S2.getsum ()). CompareTo (S1.getsum ()); returnA; }}
There are five students, each student has 3 courses (Chinese, maths, English) scores, * Write a program to receive information from the keyboard input students, the input format is: name,30,30,30 (name, three class results)