Student management system
The steps are as follows :
A: Define student class
B: The main interface code of student management system
C: Student management system to see all the students code
D: Student management system to add student code
E: Student management system to delete student code
F: Student management system to modify the student code

Student class
package StudentManager; public class Student { // Define member variables private String id;
private String name; private String age; private String address; // Generating nonparametric construction method
public Student() { // super(); // TODO Auto-generated constructor stub }
// Generating parametric construction method public Student(String id, String name, String age, String address) {
// super(); this.id = id; this.name = name; this.age = age; this.address =
address; } // generate get set method public String getId() { return id; } public void
setId(String id) { this.id = id; } public String getName() { return name; }
public void setName(String name) { this.name = name; } public String getAge() {
return age; } public void setAge(String age) { this.age = age; } public String
getAddress() { return address; } public void setAddress(String address) {
this.address = address; } }
Test class
package StudentManager; import java.sql.Array; import java.util.ArrayList;
import java.util.Scanner; /* The steps are as follows : A: Define student class B: The main interface code of student management system
C: Student management system to see all the students code D: Student management system to add student code E: Student management system to delete student code F: Student management system to modify the student code
*/ public class StudentMannagerTest { public static void main(String[] args) {
// TODO Auto-generated method stub // Create a collection object , Used to store student data ArrayList<Student> array
= new ArrayList<Student>(); // Use cycle , Let the program return to the main interface while (true) { // Main interface of student management system
System.out.println("**************"); System.out.println("* Student management system *");
System.out.println("**************"); System.out.println("1 View all students ");
System.out.println("2 Add students "); System.out.println("3 Delete students ");
System.out.println("4 Revise students "); System.out.println("5 sign out ");
System.out.println(" Please enter your choice :"); // Create keyboard entry object Scanner sc = new
Scanner(System.in); String choiceString = sc.nextLine(); //
switch Statement in jdk1.7 After that, a string can be placed in the position of the expression switch (choiceString) { case "1": // View all students
findAllStudent(array); break; case "2": // Add student addStudent(array); break;
case "3": // Delete students deleteStudent(array); break; case "4": // Revise students
updateStudent(array); break; case "5": // sign out System.out.println(" Thank you for your use
...");// case pierce through : These two lines can be omitted . System.exit(0); break; default:
System.out.println(" Thank you for your use ..."); System.exit(0);// JVM sign out break;// end switch } }
// true } // Revise students private static void updateStudent(ArrayList<Student> array) {
// TODO Auto-generated method stub //
Revise students' thinking : Enter a student number on the keyboard , Look in the collection , See if any students use the student number , If so, modify the student Scanner sc = new
Scanner(System.in); System.out.println(" Please input the student number of the student you want to modify :"); String id =
sc.nextLine(); // Judge whether the entered student number exists // Define an index int index = -1; // Traversal set for (int x = 0;
x < array.size(); x++) { // Get each student object Student s = array.get(x); //
Compare the student number of the student object with the one entered by the keyboard if (s.getId().equals(id)) { index = x; break; } } if
(index == -1) { System.out.println(" sorry , The student information corresponding to the student number you want to modify does not exist , Please go back and make your choice again ..."); }
else { System.out.println(" Please enter the new name of the student :"); String name = sc.nextLine();
System.out.println(" Please enter the new age of the student :"); String age = sc.nextLine();
System.out.println(" Please enter the student's new residence :"); String address = sc.nextLine(); // Creating student objects
Student s = new Student(); s.setId(id); s.setName(name); s.setAge(age);
s.setAddress(address); // Modify student objects in the collection *********** array.set(index, s); // Give a hint
System.out.println(" Modify student success "); } } // Delete students private static void
deleteStudent(ArrayList<Student> array) { // TODO Auto-generated method stub //
Delete students' ideas : Enter a student number on the keyboard , Look in the collection , See if any students use the student number , If so, delete the student Scanner sc = new
Scanner(System.in); System.out.println(" Please enter the student number of the student you want to delete :"); String id =
sc.nextLine(); /* * // Traversal set for(int x=0; x<array.size(); x++) { // Get every student object
Student s = * array.get(x); // Compare the student number of this student object with the student number entered on the keyboard if(s.getId().equals(id)) {
* array.remove(x); // Delete by index break;// Student number is not repeated } } // Give a hint *
System.out.println(" Delete student successfully "); */ // Give the prompt when the student number does not exist ***** Change key code // Define an index int index
= -1; // Traversal set for (int x = 0; x < array.size(); x++) { // Get every student object Student s
= array.get(x); // Compare the student number of this student object with the student number entered on the keyboard if (s.getId().equals(id)) { index =
x; break; } } if (index == -1) {
System.out.println(" sorry , The student information corresponding to the student number you want to delete does not exist , Please go back and make your choice again ..."); } else {
array.remove(index); System.out.println(" Delete student successfully "); } } // Add students private static
void addStudent(ArrayList<Student> array) { // TODO Auto-generated method stub
Scanner sc = new Scanner(System.in); // In order to make id Can be accessed , hold id It's defined outside the loop String id; //
To get the code back here , With circulation while (true) { System.out.println(" Please input student number :");// If occupied , Back in the business //
String id = sc.nextLine(); id = sc.nextLine(); // Judge whether the student number is occupied or not // Defining Tags boolean
flag = false; // Traversal set , Get every student for (int x = 0; x < array.size(); x++) { Student
s = array.get(x); // Get the student number of the student , Compare with the student number entered by keyboard if (s.getId().equals(id)) { flag =
true; // flag Was amended to read true, It means the student number is occupied break; } } if (flag) {
System.out.println(" The student number you entered has been occupied , Please re-enter ...");// If occupied } else { break; //
end while loop } } // System.out.println(" Please input student number :"); // String id = sc.nextLine();
System.out.println(" Please enter the name of the student :"); String name = sc.nextLine();
System.out.println(" Please enter the age of the student :"); String age = sc.nextLine();
System.out.println(" Please enter the student's residence :"); String address = sc.nextLine(); // Creating student objects
Student s = new Student(); s.setId(id);// assignment s.setName(name); s.setAge(age);
s.setAddress(address); // Add student objects to the collection as elements array.add(s); // Give a hint
System.out.println(" Add student successfully "); } // View all students private static void
findAllStudent(ArrayList<Student> array) { // TODO Auto-generated method stub
// First, to determine whether there is data in the set , If there is no data , Give a hint , And let the method not continue if (array.size() == 0) {
System.out.println(" sorry , At present, there is no student information to inquire about , Please go back and select your operation again ..."); return;// Method does not continue } //
Traversal set System.out.println(" Student number \t full name \t Age \t Residence "); for (int x = 0; x < array.size();
x++) { Student s = array.get(x); System.out.println(s.getId() + "\t" +
s.getName() + "\t" + s.getAge() + "\t" + s.getAddress()); } } }
result :
************** * Student management system * ************** 1 View all students 2 Add students 3 Delete students 4 Revise students 5 sign out
Please enter your choice : 1 sorry , At present, there is no student information to inquire about , Please go back and select your operation again ... ************** * Student management system *
************** 1 View all students 2 Add students 3 Delete students 4 Revise students 5 sign out Please enter your choice : 2 Please input student number : 123456
Please enter the name of the student : Zhang San Please enter the age of the student : 20 Please enter the student's residence : Beijing Add student successfully ************** * Student management system *
************** 1 View all students 2 Add students 3 Delete students 4 Revise students 5 sign out Please enter your choice : 2 Please input student number : 1234567
Please enter the name of the student : WangTwo Please enter the age of the student : 21 Please enter the student's residence : Xi'an Add student successfully ************** * Student management system *
************** 1 View all students 2 Add students 3 Delete students 4 Revise students 5 sign out Please enter your choice : 1 Student number full name Age Residence 123456 Zhang San
20 Beijing 1234567 WangTwo 21 Xi'an ************** * Student management system * ************** 1 View all students 2 Add students
3 Delete students 4 Revise students 5 sign out Please enter your choice : 4 Please input the student number of the student you want to modify : 1234567 Please enter the new name of the student : Li Si Please enter the new age of the student : 22
Please enter the student's new residence : Beijing Modify student success ************** * Student management system * ************** 1 View all students 2 Add students
3 Delete students 4 Revise students 5 sign out Please enter your choice : 1 Student number full name Age Residence 123456 Zhang San 20 Beijing 1234567 Li Si 22 Beijing
************** * Student management system * ************** 1 View all students 2 Add students 3 Delete students 4 Revise students 5 sign out Please enter your choice :
5 Thank you for your use ...

Technology