In my spare time, I wrote a management system for student information in JAVA. Since bloggers are still newbie, the code is inevitably redundant and wrong. If you find any shortcomings or errors, please leave a message. The blogger will try to reply.
Requirements Analysis
A student information management system should contain these contents:
Teachers' Page
On the teacher page, it should include:
Student Page
On the teaching student page, it should include:
Included classes
According to the analysis, our student information system should contain three categories:
Code
Student category
Student.java
package com.gcl;import com.sun.org.glassfish.external.statistics.AverageRangeStatistic;import java.util.Scanner;/** * Created by GCL on 2017/4/22. */public class Student{ private int number; //student number private String name; //name private int age; //age private double grade[]=new double[100]; //score private String project[]=new String[100]; //name private double average; //average score private int count; //Number of subjects public void setNumber(int num) { this.number=num; } public int getNumber() { return number; } public void setName(String name) { this.name=name; } public String getName() { return name; } public void setAge(int age) { this.age=age; } public int getAge() { return age; } public void setGrade(double a[]) { System.arraycopy(a, 0, grade, 0, a.length); } public void setGrade(double a[]) { System.arraycopy(a, 0, grade, 0, a.length); } public double getGrade(int i) { return grade[i]; } public void setProject(String a[]) { System.arraycopy(a,0,project,0,a.length); this.count=a.length; } public String getProject(int i) { return project[i]; } public void setAverage(int len) { double sum=0; int i=0; for (;i<len;i++) { sum+=grade[i]; } this.average=sum/(i*1.0); } public double getAverage() { return average; } public int getCount() { return count; }}Account password category
Imfomation .java
package com.gcl;/** * Created by GCL on 2017/5/6. */public class Imfomation { private String code; private String account; public Imfomation(String admin, String s) { this.account=admin; this.code=s; } public void setCode(String code) { this.code=code; } public String getCode() { return code; } public void setAccont(String account) { this.account=account; } public String getAccont() { return account; }}System operation class
MAIN.java
package com.gcl;import java.util.Objects;import java.util.Scanner;/** * Created by GCL on 2017/5/7. */public class MAIN { private static int m=0; //Number of subjects private static int n=0; //Number of students private static String[] a=new String[50]; private static Imfomation ac=new Imfomation("Admin","123456"); //Initialize teacher account password private static Student su[]=new Student[100]; //Instantiate the student class array public static void main(String[] args) { show(); //Enter the system initial page} //System initial page private static void show() { System.out.println("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("Please enter the account name: "); String c=in.nextLine(); if (!Objects.equals(c, ac.getAccont())) { System.out.println("Account does not exist!"); MAIN.Login(ac); } System.out.println("Please enter the password: "); String b=in.nextLine(); { if (!Objects.equals(b, ac.getCode()))) { System.out.println("Password error!"); MAIN.Login(ac); } } System.out.println("Login successfully!"); MAIN.Teacher(); } //Teacher main page private static void Teacher() { System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("-----3.Show student information----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Search(1); else if (c==3) Show(); else if (c==4) Delete(); else if (c==5) Renew(); else if (c==6) Recode(); else if (c==0) show(); else { System.out.println("Input error!"); Teacher(); } } //Student homepage private static void Student() { System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------"); System.out.println("--------------------------------------"); System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- double[] g=new double[50]; while(true) { su[n]=new Student(); System.out.println("Please enter the student number:"); Scanner in=new Scanner(System.in); num1=in.nextInt(); for (int i=0;i<n;i++) //Check whether the student number is repeated { while(su[i].getNumber() == num1) { System.out.println("The student number already exists, please re-enter:"); num1=in.nextInt(); } } su[n].setNumber(num1); System.out.println("Please enter the student's name: "); str=in.next(); su[n].setName(str); System.out.println("Please enter the student's age:"); t=in.nextInt(); su[n].setAge(t); if (n==0) //When creating the first student, create the number and name of the subjects at the same time { System.out.println("Please enter N courses"); m=in.nextInt(); System.out.println("Please enter the subject name of "+m+" respectively: "); for(int i=0;i<m;i++) { a[i]=in.next(); } } su[n].setProject(a); for (int i=0;i<m;i++) { System.out.println("Please enter"+su[n].getProject(i)+"Subject score: "); g[i]=in.nextInt(); } su[n].setGrade(g); su[n].setAverage(m); n++; System.out.println("Do you continue to add? (Y/Y, no/N)"); String cho=in.next(); char ch=cho.charAt(0); if (ch=='N'||ch=='n') Teacher(); //Return to the teacher's main page while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') { System.out.println("The input is invalid, please re-enter: "); cho=in.next(); ch=cho.charAt(0); } } } //Show student information private static void Show() { System.out.println("Student information is as follows: "); for (int i=0;i<n;i++) { System.out.println("Things"+i+" name student: "); System.out.println("Student number: "+su[i].getNumber()+"/tName: "+su[i].getName()+"/tAge:"+su[i].getAge()); System.out.println("The student's grades are: "); for (int j=0;j<m;j++) { System.out.println(su[i].getProject(j)+":/t"+su[i].getGrade(j)); } System.out.println("The student's average score is: "+su[i].getAverage()); } System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); Teacher(); } //Search student information, the parameters are used to determine whether the student or teacher accessing the function private static void Search(int jud) { System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ System.out.println("---0. Return to main menu----"); System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- System.out.println("Student number: "+su[i].getNumber()+"/tName: "+su[i].getName()+"/tAge:"+su[i].getAge()); System.out.println("The student's grades are: "); for (int j=0;j<m;j++) { System.out.println(su[i].getProject(j)+":/t"+su[i].getGrade(j)); } System.out.println("The student's average score is: "+su[i].getAverage()); System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); if (jud==1) //If it is a teacher visit, return Teacher() Teacher(); Student(); //Otherwise return Student() } } System.out.println("The student was not found, it will be returned soon"); if (jud==1) Teacher(); Student(); } else if (ch==2) { System.out.println("Please enter your name:"); String na=In.next(); for (int i=0;i<n;i++) { if (Objects.equals(su[i].getName(), na)) { System.out.println("Search number: "+su[i].getNumber()+"/tName: "+su[i].getName()+"/tAge:"+su[i].getAge()); System.out.println("The student's grades are:"); for (int j=0;j<m;j++) { System.out.println(su[i].getProject(j)+":/t"+su[i].getGrade(j)); } System.out.println("The student is averagely divided into: "+su[i].getAverage()); temp=true; } } if (temp) { System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); if (jud==1) Teacher(); Student(); } else { System.out.println("The student was not found, will be returned soon"); if (jud==1) Teacher(); Student(); } } else if (ch==0) { if (jud==1) Teacher(); Student(); } else { System.out.println("Input error!"); Search(jud); } } //Delete student information private static void Delete() { System.out.println("Please enter the student number of the student to be deleted:"); Scanner In=new Scanner(System.in); int num=In.nextInt(); boolean temp=true; //Determine whether the student is found int tem=0,i=0; for (i=0;i<n;i++) { if (su[i].getNumber()==num) { temp=false; tem=i; //Use tem to record the student's location break; } } if (temp) { System.out.println("The student information was not found"); System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); Teacher(); } else { System.out.println("The student information you want to delete:"); System.out.println("Student number: "+su[tem].getNumber()+"/tName: "+su[tem].getName()+"/tAge:"+su[tem].getAge()); System.out.println("The student's grades are: "); for (int j=0;j<m;j++) { System.out.println(su[tem].getProject(j)+":/t"+su[tem].getGrade(j)); } System.out.println("The student's average score is: "+su[tem].getAverage()); System.out.println("Are you sure you want to delete the student? (Y/Y, No/N)"); String ch=In.next(); char se=ch.charAt(0); while(se!='N'&&se!='n'&&se!='Y'&&se!='y') { System.out.println("Input is invalid, please re-enter:"); ch=In.next(); se=ch.charAt(0); } if (se=='N'||se=='n') { System.out.println("Return to main menu"); Teacher(); } if (se=='Y'||se=='y') //Delete the student's information through the linear table deletion operation { for (i=tem;i<n-1;i++) { su[i]=su[i+1]; } n--; System.out.println("Student information is deleted successfully!"); System.out.println("Input any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); Teacher(); } } } //Modify student information private static void Renew() { System.out.println("Please enter the student number of the student to be modified:"); Scanner In=new Scanner(System.in); int num=In.nextInt(); boolean temp=true; int tem=0,i=0; for (i=0;i<n;i++) { if (su[i].getNumber()==num) { temp=false; tem=i; break; } } if (temp) { System.out.println("The student information is not found"); System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); Teacher(); } else { System.out.println("The student information you want to modify is as follows:"); System.out.println("The student information you want to modify:"); System.out.println("Student number: "+su[tem].getNumber()+"/tName: "+su[tem].getName()+"/tAge:"+su[tem].getAge()); System.out.println("The student's grades are:"); for (int j=0;j<m;j++) { System.out.println(su[tem].getProject(j)+":/t"+su[tem].getGrade(j)); } System.out.println("The student is averagely divided into: "+su[tem].getAverage()); System.out.println("Are you sure you want to modify the student? (Y/Y, No/N)"); String ch=In.next(); char se=ch.charAt(0); while(se!='N'&&se!='n'&&se!='Y'&&se!='y') { System.out.println("Input is invalid, please re-enter:"); ch=In.next(); se=ch.charAt(0); } if (se=='N'||se=='n') { System.out.println("Return to main menu"); Teacher(); } if (se=='Y'||se=='y') { double[] g=new double[50]; System.out.println("Please select the modified content: "); //Select which content to modify System.out.println("---1. Modify name----"); System.out.println("---2. Modify age-----"); System.out.println("---3. Modify grade-----"); System.out.println("---0. Return to main menu--"); int cho=In.nextInt(); if (cho==1) { System.out.println("Please enter your name:"); String name=In.next(); su[tem].setName(name); System.out.println("Modification was successful!"); System.out.println("Do you still need to continue modifying? (Y/Y, No/N)"); ch=In.next(); se=ch.charAt(0); while (se!='N'&&se!='n'&&se!='Y'&&se!='y') { System.out.println("Input is invalid, please re-enter:"); ch=In.next(); se=ch.charAt(0); } if (se=='N'||se=='n') { System.out.println("Return to main menu"); Teacher(); } if (se=='y'||se=='Y') { Renew(); } } else if (cho==2) { System.out.println("Please enter age:"); int ag=In.nextInt(); su[tem].setAge(ag); System.out.println("Modification successful!"); System.out.println("Do you still need to continue modifying? (Yes/Y, no/N)"); ch=In.next(); se=ch.charAt(0); while (se!='N'&&se!='n'&&se!='Y'&&se!='y') { System.out.println("Input.println("Input is invalid, please re-enter:"); ch=In.next(); se=ch.charAt(0); } if (se=='N'||se=='n') { System.out.println("Return to main menu"); Teacher(); } if (se=='y'||se=='Y') { Renew(); } } else if (cho==3) { for (int j=0;j<m;j++) { System.out.println("Please enter"+su[tem].getProject(j)+"Subject score: "); g[j]=In.nextInt(); } su[tem].setGrade(g); su[tem].setAverage(m); System.out.println("Modify successfully!"); System.out.println("Do you still need to continue modifying? (Y/Y, no/N)"); ch=In.next(); se=ch.charAt(0); while (se!='N'&&se!='n'&&se!='Y'&&se!='y') { System.out.println("Input is invalid, please re-enter:"); ch=In.next(); se=ch.charAt(0); } if (se=='N'||se=='n') { System.out.println("Return to main menu"); Teacher(); } if (se=='y'||se=='Y') { Renew(); } } else if (cho==0) { Teacher(); } else { System.out.println("Invalid input!"); Renew(); } } } } //Modify the teacher's password private static void Recode() { System.out.println("Please enter the original password:"); Scanner In=new Scanner(System.in); String code =In.nextLine(); if (!Objects.equals(code, ac.getCode()))) { System.out.println("Password entry error!"); Teacher(); } System.out.println("Please enter a new password:"); //Require new password twice String co1=In.nextLine(); System.out.println("Please enter a new password again:"); String co2=In.nextLine(); if (!Objects.equals(co1, co2)) { System.out.println("The password is inconsistent when two times are entered!"); System.out.println("Return to the main interface soon"); Teacher(); } else { ac.setCode(co1); System.out.println("Password modification was successful!"); System.out.println("Enter any value to return to the main menu"); Scanner in=new Scanner(System.in); in.next(); Teacher(); } }}For more learning materials, please pay attention to the special topic "Management System Development".
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.