The examples in this article share the specific code of the Java student information management system to realize student information: Add int[] a=new int[9], delete, search, and change for your reference. The specific content is as follows
/*Student information management system, implement student information: *Add int[] a=new int[9] *Delete*Find*Change*/ import java.util.Scanner;//Import java input stream import java.lang.*; import java.io.*; class Student { private static Student[] s=new Student[2]; int n=0; private String name; private int num; private String classAge; public void judge()throws IOException { int i; char ch; String str; Scanner In=new Scanner(System.in); if(n==0) { System.out.print("You have not entered any student yet, whether to enter (Y/N):"); str=In.next(); ch=str.charAt(0); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { System.out.print("Input.print("If the 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(); } } } public void menu()throws IOException//Define menu function { int a;//Define switch statement variable Scanner in=new Scanner(System.in);//Instantiate the input stream object System.out.println("********* Student Information Management System Function Table**********"); System.out.println("****** 1. Add *******"); System.out.println("****** 2. Show ****"); System.out.println("****** 3. Modify ****"); System.out.println("****** 4. Delete ****"); System.out.println("****** 5.View****"); System.out.println("****** 0.Exit*******"); System.out.println("*********************************************"); System.out.print("Please select (0~5):"); a=in.nextInt(); while(a<0||a>5) { System.out.print("Input is out of range, 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.exit(0);break; } } public void add()throws IOException//Define the addition function { String str,str1,str2; int i,num1,t=1; char ch,ch1; FileWriter fw=new FileWriter("F://javaFile//student.txt",true); fw.write(" List of entered student information /r/n/r/n student number name class /r/n"); Scanner In=new Scanner(System.in); while(t==1) { System.out.print("Please enter student number:"); num1=In.nextInt(); 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.print("Please enter the student name:"); s[n].name=In.next(); fw.write(s[n].name+" "); System.out.println(); System.out.print("Please enter the student class:"); s[n].classAge=In.next(); fw.write(s[n].classAge+"/r/n"); ++n; fw.close(); System.out.println(); System.out.print("Do you continue to add (Y/N)"); str=In.next(); ch=str.charAt(0); while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') { System.out.print("Input.print("If the input is incorrect, 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 main menu (Y/N)"); str1=In.next(); ch1=str1.charAt(0); while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n') { System.out.print("Input.print("If there is an error, 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("Exiting...Thanks for using!"); System.exit(0); } } 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/t/tname/t class"); for(i=0;i<n;i++) { System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge); } System.out.println("System returns to the main menu!"); this.menu(); } public void delete()throws IOException//Implementation of the deleted information function Note: This function is not extensible for the time being { this.judge(); int j=0,t=0,k=0,num1; char ch; String str; Scanner pin=new Scanner(System.in); System.out.print("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/tname/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.print("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.print("Input.print("If the input is incorrect, 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("Data was deleted successfully!"); System.out.println("System returns to the main menu!"); this.menu(); } } } public void look()throws IOException { FileReader fr=new FileReader("F://javaFile//student.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(); } public void modify()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.print("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) { System.out.println("The student information you want to modify 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.print("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.print("Input is incorrect, 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 the class *******"); System.out.println("****** 3. Modify the name *******"); System.out.println("*********************************************************"); System.out.print("Please select:"); moi=pin.nextInt(); switch(moi) { case 1:System.out.print("Please enter the new student number:");num3=pin.nextInt();s[t].num=num3;break; case 2:System.out.print("Please enter the 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 incorrect, 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<2;i++) { s[i]=new Student(); } stu.menu(); } }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.