Java Collection Student Management system

Source: Internet
Author: User

Student.javapackage Com.sran.www;import Java.util.arrays;import Java.util.scanner;public class student implements Comparable<student>{int num; String name;int age;double[]s;double sum; Store student's total score public Student () {s=new double[3];} public static Boolean insert () {Scanner sc=new Scanner (system.in); String Str=null;boolean be=true;do{student stud=new Student (); System.out.println ("Start typing information about students ..."); System.out.print ("Study No.:"); Stud.num=sc.nextint (); System.out.print ("Name:"); Stud.name=sc.next (); System.out.print ("Age:"); Stud.age=sc.nextint (); System.out.println ("Enter the results of each class in turn:"); System.out.print ("Language:"); stud.s[0]=sc.nextdouble (); System.out.print ("Mathematics:"); stud.s[1]=sc.nextdouble (); System.out.print ("English:"); stud.s[2]=sc.nextdouble (); Stud.sum=stud.calculate_sum (); StudentTest.set.add (stud); SYSTEM.OUT.PRINTLN ("If continued input, then enter%, otherwise enter #"); System.out.print ("Please enter:"); Str=sc.next (); if (! ( Str.equals ("%") | | Str.equals ("#"))) {be=false; SYSTEM.OUT.PRINTLN ("You entered the error, has been forced to end the entry operation");}} while (Str.equals ("%") && be); return is;} Public Static Boolean Delete () {String Str=null;boolean be=true; System.out.println ("Start deleting information about students ...");d o{system.out.print ("Please enter the student number for deletion:");  Scanner sc=new Scanner (system.in); int S=sc.nextint (); Boolean flag=false; Set a flag bit for (Student Stud:StudentTest.set) {if (s==stud.num) {StudentTest.set.remove (stud); flag=true; System.out.println ("The student's information has been deleted"); if (flag==false) {System.out.println ("the student number you want to delete does not exist");} System.out.println ("If you continue to delete, enter%, otherwise enter #"); System.out.print ("Please enter:"); Str=sc.next (); if (! ( Str.equals ("%") | | Str.equals ("#"))) {be=false; SYSTEM.OUT.PRINTLN ("You entered the error, the delete operation was forced to end");}} while (Str.equals ("%") && be); return is;} public static Boolean Seek () {String Str=null;boolean be=true; System.out.println ("Start looking up information about students ...");d o {System.out.print ("Please enter the student number to find:"); Scanner sc=new Scanner (system.in); int S=sc.nextint (); Boolean flag=false;for (Student stud:StudentTest.set) {if (s==  Stud.num) {flag=true; Modify the flag bit System.out.println ("You want to find the student's information:"); System.out.println ("Study No.:" +stud.num); System.out.println ("Name:" +stud.name); SysTem.out.println ("Age:" +stud.age); System.out.println ("Language achievement:" +stud.s[0]); System.out.println ("Math score:" +stud.s[1]); System.out.println ("English score:" +stud.s[2]); break;}} if (flag==false) {System.out.println ("The student number you are looking for does not exist");} System.out.println ("If you continue to find, enter%, otherwise enter #"); System.out.print ("Please enter:"); Str=sc.next (); if (! ( Str.equals ("%") | | Str.equals ("#"))) {be=false; SYSTEM.OUT.PRINTLN ("You entered the error, have forced the end of the query operation");}} while (Str.equals ("%") && be); return is;} Public double calculate_sum () {Sum=s[0]+s[1]+s[2];return sum;} @Overridepublic int compareTo (Student stud) {this.sum=this.calculate_sum (); Stud.sum=stud.calculate_sum (); if (  This.sum>stud.sum) Return-1;else if (this.sum<stud.sum) return 1;else{if (This.name.compareTo (stud.name) >0) Return-1;else if (This.name.compareTo (stud.name) <0) return 1;elsereturn 0;}} Public String toString () {System.out.println ("study number" + "\t\t" + "name" + "\t\t" + "age" + "\t\t" + "language" + "\t\t" + "math" + "\t\t" + "English" + "\ T \ t "+" total Score ") Return (num+" \t\t "+name+" \t\t "+age+" \t\t "+s[0]+" \t\t "+s[1]+" \t\t "+s[2]+" \t\t "+sum);} PublIC Static Boolean update () {String Str=null;boolean bot=true; System.out.println ("Start updating student information ...");d o{system.out.print ("Please enter the student number to be updated:"); Scanner sc=new Scanner (system.in); int S=sc.nextint (); Boolean Be=false;boolean br=false;for (Student Stud: Studenttest.set) {if (stud.num==s) {be=true;//modifies the flag bit System.out.println ("Enter which item to update: Where 1 represents the study number, 2 represents the name, 3 represents the age, 4 represents the language score, 5 for mathematical results, 6 for English score "); System.out.print ("Please enter:"); int n=sc.nextint (); switch (n) {case 1:{system.out.print ("Please enter the modified number:"); stud.num=sc.nextint (); SYSTEM.OUT.PRINTLN ("modified success"); Case 2:{system.out.print ("Please enter the modified name:"); Stud.name=sc.next (); SYSTEM.OUT.PRINTLN ("modified success"); Case 3:{system.out.print ("Please enter the Modified Age:"); Stud.age=sc.nextint (); SYSTEM.OUT.PRINTLN ("modified success"); Case 4:{system.out.print ("Please enter the revised language score:"); stud.s[0]=sc.nextdouble ();  SYSTEM.OUT.PRINTLN ("modified successfully"); Stud.sum=stud.calculate_sum (); Re-update the total score br=true;break;} Case 5:{system.out.print ("Please enter the revised Math score:"); stud.s[1]=sc.nextdouble ();  SYSTEM.OUT.PRINTLN ("modified successfully"); Stud.sum=stud.calculate_sum (); Re-update the total score br=true;break;} CaSe 6:{system.out.print ("Please enter the revised English score:"); stud.s[2]=sc.nextdouble ();  SYSTEM.OUT.PRINTLN ("modified successfully"); Stud.sum=stud.calculate_sum (); Re-update total Br=true;break;}}} if (br==true) {Object[]obj=studenttest.set.toarray (); Arrays.sort (obj); StudentTest.set.clear (); for (int i=0;i<obj.length;i++) {Student st= (Student) obj[i]; StudentTest.set.add (ST);}} if (be==false) {System.out.println ("You want to modify the student's number does not exist");} System.out.println ("If you continue to modify, enter%, otherwise enter #"); System.out.print ("Please enter:"); Str=sc.next (); if (! ( Str.equals ("%") | | Str.equals ("#"))) {bot=false; SYSTEM.OUT.PRINTLN ("You entered the error, the update operation was forced to end");}} while (Str.equals ("%") && bot); return bot;}}

Studenttestpackage com.sran.www;import java.util.scanner;import Java.util.set;import java.util.TreeSet;public  Class Studenttest {static set<student>set=null;  Define collection, store student information public void fun () {int I;boolean b,bt;set=new treeset<student> (); Do{int flag=0; System.out.println ("Please enter 1,2,3,4,5 1 for input, 2 for deletion, 3 for search, 4 for the total student score, and 5 for updating a student data"); System.out.print ("Please enter:"); Scanner sc=new Scanner (system.in); int n=sc.nextint (); switch (n) {case 1:{b=student.insert (); if (b==true) { System.out.println ("Normal End entry operation ...");} Flag=1;break;} Case 2:{b=student.delete (); if (b==true) {System.out.println ("normal end delete operation ..."); Flag=1;break;} Case 3:{b=student.seek (); if (b==true) {System.out.println ("normal end query operation ..."); Flag=1;break;} Case 4:{system.out.println ("Start ranking student information ....."); SYSTEM.OUT.PRINTLN ("Student ranked by total score:"); for (Student Stud:set) {System.out.println (stud); System.out.println ();} System.out.println ("Normal end ranking operation ..."); flag=1;break;} Case 5:{b=student.update (); if (b==true) {System.out.println ("normal End update operation ...");} Flag=1;break;}} if (flag==0{SYSTEM.OUT.PRINTLN ("you entered the wrong, please re-enter");} System.out.println ();d o {bt=false; System.out.println ("Continue all student information operation, please enter 1 exit Student information System, please enter 0"); System.out.print ("Please enter:"); I=sc.nextint (); if (i!=1 && i!=0) {bt=true; SYSTEM.OUT.PRINTLN ("Input error, please re-enter");}} while (bt==true);} while (i==1); SYSTEM.OUT.PRINTLN ("You have exited student information system .....");} public static void Main (string[] args) {new Studenttest (). Fun ();}}

Java Collection Student Management system

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.