Java programming: There are five students, each student has 3 courses (Chinese, maths, English) scores,

Source: Internet
Author: User

1 import Java.io.FileReader;2 import Java.io.FileWriter;3 import java.io.IOException;4 import java.util.Collections;5 import Java.util.Comparator;6 import java.util.LinkedList;7 import Java.util.Scanner;8  9  Public classStudentTen { One     DoubleChinese; A     DoubleMath; -     Double中文版; -     Doublesum; the String sname; -   -      PublicStudent (DoubleChinese,DoubleMathDouble中文版,Doublesum, String sname) -     { +          This. Chinese =Chinese; -          This. Math =Math; +          This. 中文版 =中文版; A          This. sum =sum; at          This. sname =sname; -     } -   - @Override -      PublicString toString () -     { in         returnString.Format ("%s\t\t%2$.1f\t\t\t%3$.1f\t\t\t%4$.1f\t\t\t%5$.1f", Sname, Chinese, math, 中文版, sum); -     } to   +      Public Static voidMain (string[] args) -     { theScanner Scanner =NewScanner (System.inch); *linkedlist<student> list =NewLinkedlist<student> (); $System. out. println ("Enter the student's information from the keyboard, enter the format as: name,30,30,30 (name, <a href="Https//www.baidu.com/s?wd=%E4%B8%89%E9%97%A8&tn=44039180_cpr&fenlei= Mv6quakxtzn0izrqihckpjm4nh00t1yvuhnkuwn-njmvnypbpwnv0zwv5hcvrjm3rh6spfkwumw85hfynjn4nh6sgvpst6k1tl0qnfk1tl0z5hd0igf _5y9yiz0lqzqlpa-bmyt8mh7guzr8mvqvql7dugpypyq8q1dlpwt3pwr3rjrlpjfdrhrvp0 "target=" _blank "class=" baidu-highlight " > Sanmen </a>) < direct return to end > ");Panax Notoginseng          while(Scanner.hasnextline ()) -         { theString line =scanner.nextline (). Trim (); +             if("". Equals (line)) A             { the                  Break; +             } -String[] Info = line.split ("\\,"); $String name = info[0]; $             DoubleChinese =0; -             DoubleMath =0; -             Double中文版 =0; the             Doublesum =0; -             TryWuyi             { theChinese = double.parsedouble (info[1]); -Math = double.parsedouble (info[2]); Wu中文版 = double.parsedouble (info[3]); -sum = Chinese + math +中文版; About             } $             Catch(Exception e) -             { -System. out. println ("format is incorrect, rewrite input:"); -                 Continue; A             } +Student Student =NewStudent (Chinese, math, 中文版, sum, name); the List.add (student); -         } $ scanner.close (); theCollections.sort (list,NewComparator<student> () the         { the @Override the              Public intCompare (Student O1, Student O2) -             { in                 if(O1.sum >o2.sum) the                 { the                     return-1; About                 } the                 Else if(O1.sum <o2.sum) the                 { the                     return 1; +                 } -                 Else the                 {Bayi                     return 0; the                 } the             } -         }); -         Try the         { theString file ="Stu.txt"; theString line = System.getproperty ("Line.separator"); theFileWriter FW =NewFileWriter (file,true); -FileReader FR =Newfilereader (file); the             if(Fr.read () = =-1) the             { theFw.write ("name \t\t Chinese \t\t mathematics \t\t<a href="Https//www.baidu.com/s?wd=%E8%8B%B1%E8%AF%AD&tn=44039180_cpr&fenlei= Mv6quakxtzn0izrqihckpjm4nh00t1yvuhnkuwn-njmvnypbpwnv0zwv5hcvrjm3rh6spfkwumw85hfynjn4nh6sgvpst6k1tl0qnfk1tl0z5hd0igf _5y9yiz0lqzqlpa-bmyt8mh7guzr8mvqvql7dugpypyq8q1dlpwt3pwr3rjrlpjfdrhrvp0 "target=" _blank "class=" baidu-highlight " > English </a>\t\t total score "+ line);94             } the fr.close (); the              for(Student student:list) the             {98Fw.write (student.tostring () +Line ); About Fw.flush (); -             }101 fw.close ();102System. out. println ("join complete.");103         }104         Catch(IOException e) the         {}106     }107}

Java programming: There are five students, each student has 3 courses (Chinese, maths, English) scores,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.