In fact, as a Java program ape, whether you are beginner or big God, student management system has always been a very good example, beginners mainly with arrays, lists and so on to write a simple student management system, two, a little bit of the great God with Database + Swing to do a student management system with an interface. In fact, it's not too difficult.
Today I'm going to write a simple list to implement the Student management system:
First of all, the management system is aimed at students, so we first write the student object:
PackageBean; Public classStudent {String name; String StudentID; String sex; intgrade; PublicStudent (String name,string studentid,string sex,intgrade) { This. name=name; This. studentid=StudentID; This. Sex =sex; This. grade =grade; } Public intGetgrade () {returngrade; } PublicString GetName () {returnname; } PublicString Getsex () {returnsex; } Public voidSetgrade (intg) { This. grade =G; } PublicString Getstudentid () {returnStudentID; } }
This defines some get the current student object data of some get method, and the result modified set method, the code is very simple, do not do the detailed answer.
Just down is the text of our body.
Although we do not use swing to do the interface, but have to look at the past, so, first made a relatively simple interface:
System.out.println ("***************"); SYSTEM.OUT.PRINTLN ("* Welcome to Student Management System *"); SYSTEM.OUT.PRINTLN ("* 1: Increase student *"); SYSTEM.OUT.PRINTLN ("* 2: Delete student *"); SYSTEM.OUT.PRINTLN ("* 3: Revise results *"); SYSTEM.OUT.PRINTLN ("* 4: Query Results *"); System.out.println ("***************"); System.out.println ("The action you want to select is:");
As can be seen here, we are using a 1234来 selection project, said to have to talk about how Java obtains the data entered by the keyboard---------Scanner, to use this, the first import comes in a package:
For example here:
import java.util.*;
The next two lines of code take care of the input:
New Scanner (system.in); int choice = Sc.nextint ();
The next step is the implementation of each feature:
Packagetest;ImportJava.util.*;ImportBean. Student; Public classManager {StaticList<student> studentlist =NewLinkedlist<student>(); Public Static voidMain (string[] agrs) {select (Studentlist); } Private Static voidSelect (list<student>studentlist) {System.out.println ("***************"); System.out.println ("* Welcome to Student Management System *"); System.out.println ("* 1: Increase student *"); System.out.println ("* 2: Delete student *"); System.out.println ("* 3: Change the score *"); System.out.println ("* 4: Search Results *"); System.out.println ("***************"); System.out.println ("The action you want to select is:"); Scanner SC=NewScanner (system.in); intChoice =Sc.nextint (); Switch(choice) {//Increase student Case1: System.out.print ("Please enter the student's name:"); Scanner Sname=NewScanner (system.in); String name=Sname.nextline (); System.out.print ("Please enter the student's gender:"); Scanner Ssex=NewScanner (system.in); String Sex=Ssex.nextline (); System.out.print ("Please enter student's number:"); Scanner SId=NewScanner (system.in); String StudentID=Sid.nextline (); System.out.print ("Please enter student's score:"); Scanner Sgrade=NewScanner (system.in); intGrade =Sgrade.nextint (); Studentlist.add (NewStudent (Name,studentid,sex,grade)); System.out.println ("ADD success!!!!! "); Select (Studentlist); Break; //Delete Student scores Case2: System.out.print ("Please tell me that I need to delete the student's school number:"); Scanner Sid=NewScanner (system.in); String Sstudentid=Sid.nextline (); BooleanIsfinddelete =false; for(inti = 0; I < studentlist.size (); i++) { if(Sstudentid.equals (Studentlist.get (i). Getstudentid ())) {System.out.println ("Found the student, is deleting ..."); Studentlist.remove (i); System.out.println ("Delete Successful!!!"); Isfinddelete=true; } } if(!isfinddelete) {System.out.println ("Sorry, not found"); } select (Studentlist); Break; //Revise student grades Case3: System.out.print ("Please tell me I need to revise the student's number of grades:"); Scanner GId=NewScanner (system.in); String Gstudentid=Gid.nextline (); BooleanIsfindchange =false; for(intj = 0; J < Studentlist.size (); J + +) { if(Gstudentid.equals (Studentlist.get (j). Getstudentid ())) {System.out.println ("Found the student, is revising ..."); System.out.println ("Student's original score is" +Studentlist.get (j). Getgrade ()); System.out.print ("Please enter the student's score after the change:"); Scanner Ggrade=NewScanner (system.in); intGrade2 =Ggrade.nextint (); Studentlist.get (j). Setgrade (Grade2); System.out.println ("Modify Successful!!!"); Isfindchange=true; }Else{ } } if(!Isfindchange) {System.out.println ("Sorry, not found"); } select (Studentlist); Break; //View Student Scores Case4: System.out.print ("Please tell me I need to check the student's number:"); Scanner CId=NewScanner (system.in); String Cstudentid=Cid.nextline (); BooleanIsfinddata =false; for(inti = 0; I < studentlist.size (); i++) { if(Cstudentid.equals (Studentlist.get (i). Getstudentid ())) {System.out.println ("Name:" +Studentlist.get (i). GetName ()); System.out.println ("Gender:" +Studentlist.get (i). Getsex ()); System.out.println ("School Number:" +Studentlist.get (i). Getstudentid ()); System.out.println ("Score:" +Studentlist.get (i). Getgrade ()); Isfinddata=true; } } if(!isfinddata) {System.out.println ("Sorry, not found"); } select (Studentlist); Break; default: System.out.println ("You entered the wrong number, please re-enter:"); Break; } }}
As you can see, I put all the implementation processes in the Select () method, so that I can avoid the other operations after I have chosen an operation. Most operations rely on a for loop to traverse the operation, which is quick and easy.
The student management system is here, isn't it simple?
If in doubt, please leave a comment below, and answer for you.
Java write a simple student management system