The examples in this article share with you the specific code of the Java student score management system for your reference. The specific content is as follows
/* *@copyright by LzyRapx on 2016/4/12. *@name:java student score management system. *@function: student-related information, entry, query, statistics, modification, etc.... *@PS: If the student management system of the graphical interface is not required, it will not be done. */ import java.util.Scanner; import java.lang.*; import java.io.*; class Student { private static Student[] s=new Student[100]; //Enter student upper limit int n=0; private String name; private int num; private String classAge; private int chinese; private int math; private int english; //Judge whether student information has been entered public void judge() throws IOException { int i; char ch; String str; Scanner In=new Scanner(System.in); if(n==0) { System.out.println("You have not entered any student information yet, whether to enter (Y/N):"); str=In.next(); ch=str.charAt(0); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { System.out.println("Input is incorrect, please re-enter:"); str=In.next(); ch=str.charAt(0); } if(ch=='Y'||ch=='y') { this.add(); } if(ch=='N'||ch=='n') { this.menu(); } } } //Menu public void menu() throws IOException //Top the exception and call this method to handle the exception. If the main method also throws the exception, it is handed over to the Java virtual machine for processing, the same below. { int a; Scanner in=new Scanner(System.in); System.out.println("*************** Student Information Management System*************"); System.out.println("****** 1. Enter student information*******"); System.out.println("****** 2. Display student information*******"); System.out.println("****** 3. Modify student information*******"); System.out.println("****** 4. Delete student information*******"); System.out.println("****** 5. View student information*******"); System.out.println("****** 0. Exit the management system*******"); System.out.println("*********************************************************"); System.out.print("Please select (0~5):"); a=in.nextInt(); while(a<0||a>5) { System.out.print("Input is invalid, please re-enter:"); a=in.nextInt(); } switch(a) { case 1:this.add(); break; case 2:this.show(); break; case 3:this.modif();break; case 4:this.delete();break; case 5:this.look();break; case 0:System.out.println("Exit the system successfully!!!");System.exit(0);break; } } //Input student information public void add() throws IOException { String str,str1,str2; int i,num1,t=1; char ch,ch1; FileWriter fw=new FileWriter("E://student.txt",true); //Input student information into the specified txt file fw.write(" List of entered student information /r/n/r/n student number name Class Chinese score Mathematics score English score /r/n"); Scanner In=new Scanner(System.in); while(t==1) { System.out.println("Please enter student number:"); num1=In.nextInt(); //Judge whether the student number is repeated for(i=0;i<n;i++) { while(s[i].num==num1) { System.out.println("This student number already exists, please re-enter"); System.out.print("Please enter student number:"); num1=In.nextInt(); } } s[n].num=num1; str2=String.valueOf(num1); fw.write(str2+" "); System.out.println(); System.out.println("Please enter the student name:"); s[n].name=In.next(); fw.write(s[n].name+" "); System.out.println(); System.out.println("Please enter the student class:"); s[n].classAge=In.next(); fw.write(s[n].classAge+" "); System.out.println("Please enter the student Chinese score:"); s[n].chinese=In.nextInt(); fw.write(s[n].chinese+" "); System.out.println("Please enter student math scores:"); s[n].math=In.nextInt(); fw.write(s[n].chinese+" ""); System.out.println("Please enter student English scores:"); s[n].english=In.nextInt(); fw.write(s[n].english+"/r/n"); ++n; fw.close(); System.out.println(); System.out.println("Does it continue to add (Y/N)"); str=In.next(); ch=str.charAt(0); while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') { System.out.println("The input is invalid, please re-enter:"); str=In.next(); ch=str.charAt(0); } if(ch=='N'||ch=='n') { break; } } System.out.println(); System.out.print("Whether to return to the system main menu (Y/N)"); str1=In.next(); ch1=str1.charAt(0); while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n') { System.out.println("The input is invalid, please re-enter:"); str1=In.next(); ch1=str1.charAt(0); } if(ch1=='Y'||ch1=='y') { this.menu(); } if(ch1=='N'||ch1=='n') { System.out.println(""); System.out.println("You have exited the system!!!"); System.exit(0); } } //Show student information public void show() throws IOException { int i; this.judge(); System.out.println("This operation enters a total of "+n+" students!"); System.out.println("The student information you entered is as follows:"); System.out.println(); System.out.println("Student number/tname/tClass/tChinese/tMathematics/tEnglish"); for(i=0;i<n;i++) { System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge+" "+s[i].chinese+" "+s[i].math+" "+s[i].english); } System.out.println("System returns to the main menu!"); this.menu(); } //Delete student information public void delete() throws IOException { this.judge(); int j=0,t=0,k=0,num1; char ch; String str; Scanner pin=new Scanner(System.in); System.out.println("Please enter the student number to be deleted:"); num1=pin.nextInt(); for(j=0;j<n;j++) { if(s[j].num==num1) { k=1; t=j; } } if(k==0) { System.out.println("Sorry! The student number you want to delete does not exist!"); System.out.println("The system will return to the main menu!"); this.menu(); } if(k==1) { System.out.println("The student information you want to delete is as follows:");//Print the student information that the administrator wants to delete System.out.println("Student number/t name/t class");//This function is not currently extensible System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge); System.out.println(); System.out.println("You are sure to delete (Y/N):"); str=pin.next(); ch=str.charAt(0); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { System.out.println("The input is invalid, please re-enter:"); str=pin.next(); ch=str.charAt(0); } if(ch=='N'||ch=='n') { System.out.println(); System.out.println("System returns to the main menu!"); this.menu(); } if(ch=='Y'||ch=='y') { for(j=t;j<n-1;j++) { s[j]=s[j+1]; } n--; System.out.println("Student data was deleted successfully!"); System.out.println("System returns to the main menu!"); this.menu(); } } } //View student information public void look() throws IOException { FileReader fr=new FileReader("E://student.txt"); //View student information in txt int a; while((a=fr.read())!=-1) { System.out.print((char)a); } fr.close(); System.out.println("System returns to the main menu!"); System.out.println(); this.menu(); } //Modify student information public void modif() throws IOException { this.judge(); int j=0,t=0,k=0,num2,num3,moi,c=1; char ch; String str,str1,str2; Scanner pin=new Scanner(System.in); System.out.println("Please enter the student number to be modified:"); num2=pin.nextInt(); for(j=0;j<n;j++) { if(s[j].num==num2) { k=1; t=j; } } if(k==0) { System.out.println("Sorry! The student number you want to modify does not exist!"); System.out.println("The system will return to the main menu!"); this.menu(); } if(k==1) { //Print the student information that will be deleted System.out.println("The student information you want to modify is as follows:"); System.out.println("Student number/t name/t class"); System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge); System.out.println("Chinese/tMathematics/tEnglish"); System.out.println(s[t].chinese+" "+s[t].math+" "+s[t].english); System.out.println(); System.out.println("You are sure to modify (Y/N):"); str=pin.next(); ch=str.charAt(0); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { System.out.println("Input is invalid, please re-enter:"); str=pin.next(); ch=str.charAt(0); } if(ch=='N'||ch=='n') { System.out.println(); System.out.println("System returns to the main menu!"); this.menu(); } while(c==1) { if(ch=='Y'||ch=='y') { System.out.println("******************************************************"); System.out.println("****** 1. Modify the student number*******"); System.out.println("****** 2. Modify class****"); System.out.println("********* 3. Modify name*******"); System.out.println("*********************************************"); System.out.println("Please select:"); moi=pin.nextInt(); switch(moi) { case 1:System.out.print("Please enter a new student number:");num3=pin.nextInt();s[t].num=num3;break; case 2:System.out.print("Please enter a new class:");str1=pin.next();s[t].classAge=str1;break; case 3:System.out.print("Please enter a new name:");str2=pin.next();s[t].name=str2;break; } System.out.println("Data has been modified successfully!"); } System.out.print("Does it continue to modify (Y/N)"); str=pin.next(); ch=str.charAt(0); System.out.println(); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { System.out.print("Input is invalid, please re-enter:"); str=pin.next(); ch=str.charAt(0); } if(ch=='N'||ch=='n') { break; } } } System.out.println(); System.out.println("System returns to the main menu!"); this.menu(); } public static void main(String[] args) throws IOException { Student stu=new Student(); for(int i=0;i<100;i++) { s[i]=new Student(); } stu.menu(); } }Partial renderings:
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.