java student information management system source code

  • 2020-12-26 05:45:56
  • OfStack

This article shares the specific code of java student information management system for you, and realizes the student information: add int[] a=new int[9], delete, find, change, for your reference, the specific content is as follows


/* Student information management system to realize student information:  
 * increase  int[] a=new int[9] 
 * delete  
 * To find the  
 * To change the  
 */ 
import java.util.Scanner;// The import java The 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 haven't typed in any students, have you (Y/N):"); 
  str=In.next(); 
  ch=str.charAt(0); 
  while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
  { 
  System.out.print(" Incorrect input. 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 functions  
 { 
 int a;// define switch Statement variables  
 Scanner in=new Scanner(System.in);// Instantiate the input stream object  
 System.out.println("********* Student Information management system function sheet *********"); 
 System.out.println("*****  1. increase   *****"); 
 System.out.println("*****  2. According to   *****"); 
 System.out.println("*****  3. Modify the   *****"); 
 System.out.println("*****  4. delete   *****"); 
 System.out.println("*****  5. To view   *****"); 
 System.out.println("*****  0. exit   *****"); 
 System.out.println("****************************************"); 
 System.out.print(" Please select a (0~5):"); 
 a=in.nextInt(); 
 while(a<0||a>5) 
 { 
  System.out.print(" Input 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 increment 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 student information entered \r\n\r\n Student id   The name   The class \r\n"); 
 Scanner In=new Scanner(System.in); 
 while(t==1) 
 { 
  System.out.print(" Please enter your 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 it "); 
   System.out.print(" Please enter your 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's name :"); 
  s[n].name=In.next(); 
  fw.write(s[n].name+" "); 
  System.out.println(); 
  System.out.print(" Please enter student class :"); 
  s[n].classAge=In.next(); 
  fw.write(s[n].classAge+"\r\n"); 
  ++n; 
  fw.close(); 
  System.out.println(); 
  System.out.print(" Whether to continue to add (Y/N)"); 
  str=In.next(); 
  ch=str.charAt(0); 
  while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') 
  { 
  System.out.print(" Incorrect input. 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(" Incorrect input. 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(" Is out of ... Thank you for using !"); 
  System.exit(0); 
 } 
 } 
 
 public void show()throws IOException 
 { 
 int i; 
 this.judge(); 
 System.out.println(" This operation is input altogether "+n+" student !"); 
 System.out.println(" The student information you entered is as follows :"); 
 System.out.println(); 
 System.out.println(" Student id \t\t The name \t The class "); 
 for(i=0;i<n;i++)    
 { 
  System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge); 
 } 
 System.out.println(" The system returns to the main menu !"); 
 this.menu(); 
 } 
 
 public void delete()throws IOException// Delete information function implementation   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 you want to delete :"); 
 num1=pin.nextInt(); 
 for(j=0;j<n;j++) 
 { 
  if(s[j].num==num1) 
  { 
  k=1; 
  t=j; 
  } 
 } 
 if(k==0) 
 { 
  System.out.println(" I'm 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 id \t The name \t The class ");// This feature is not extensible for the time being  
  System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge); 
  System.out.println(); 
  System.out.print(" You're sure you want to delete it (Y/N):"); 
  str=pin.next(); 
  ch=str.charAt(0); 
  while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
  { 
  System.out.print(" Incorrect input. Please re-enter :"); 
  str=pin.next(); 
  ch=str.charAt(0); 
  } 
  if(ch=='N'||ch=='n') 
  { 
  System.out.println(); 
  System.out.println(" System returns to 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(" The 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 main menu! "); 
 System.out.println(); 
 this.menu(); 
 } 
 
 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.print(" Please enter the student number you want to modify :"); 
 num2=pin.nextInt(); 
 for(j=0;j<n;j++) 
 { 
  if(s[j].num==num2) 
  { 
  k=1; 
  t=j; 
  } 
 } 
 if(k==0) 
 { 
  System.out.println(" I'm 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 id \t The name \t The class ");// This feature is not extensible for the time being  
  System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge); 
  System.out.println(); 
  System.out.print(" You're sure you want to change it (Y/N):"); 
  str=pin.next(); 
  ch=str.charAt(0); 
  while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
  { 
  System.out.print(" Incorrect input. Please re-enter :"); 
  str=pin.next(); 
  ch=str.charAt(0); 
  } 
  if(ch=='N'||ch=='n') 
  { 
  System.out.println(); 
  System.out.println(" System returns to main menu! "); 
  this.menu(); 
  } 
  while(c==1) 
  { 
  if(ch=='Y'||ch=='y') 
  { 
   System.out.println("****************************************"); 
   System.out.println("*****  1. Modify the student id   *****"); 
   System.out.println("*****  2. Modify the class   *****"); 
   System.out.println("*****  3. Modify the name   *****"); 
   System.out.println("****************************************"); 
   System.out.print(" Please select a :"); 
   moi=pin.nextInt(); 
   switch(moi) 
   { 
   case 1:System.out.print(" Please enter your 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(" The data has been modified successfully! "); 
  } 
  System.out.print(" Whether to 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(" Incorrect input. 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 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(); 
 } 
} 

For more information, please pay attention to the topic management System Development.


Related articles: