The author these days in Review of Java knowledge, want to deepen the basic content, hands-on operation of the development of the student management system, specifically to share the code with you, needs can be used as a reference.
Import Java.util.scanner;public class Studentmanagementsystem {public static void main (string[] args) {//Do a learning Information management system, currently only supports the management of student information in the form of < name > (increase and deletion), that is, management is only the student's name information Scanner Scanner = new Scanner (system.in); Boolean flage = true; while (flage) {System.out.println ("Select the function you want to operate: \n1-Add \t2-Delete \t3-Modify \t4-query \t5-exit"); int num = Scanner.nextint (); Switch (num) {case 1:SYSTEM.OUT.PRINTLN ("Please enter the name you want to add:"); Name = Scanner.next (); BOOL = Add (name); if (bool) {SYSTEM.OUT.PRINTLN ("add success"); } else {System.out.println ("Add failed"); } break; Case 2:SYSTEM.OUT.PRINTLN ("Please enter the name you want to delete:"); String name = Scanner.next (); bool = delete (name); if (bool) {System.out.println ("delete succeeded"); } else { System.out.println ("delete failed"); } break; Case 3:SYSTEM.OUT.PRINTLN ("Please enter a name to be modified:"); Name = Scanner.next (); System.out.println ("Please enter the modified name"); String newName = Scanner.next (); BOOL = Update (name, newName); if (bool) {SYSTEM.OUT.PRINTLN ("modified successfully"); } else {System.out.println ("failed to modify"); } break; Case 4:print (); Break Case 5:system.out.println ("Welcome to the next use, Goodbye!") "); Flage = false; Break DEFAULT:SYSTEM.OUT.PRINTLN ("Select Error, please re-enter"); Break }} scanner.close (); } public static String name; public static Boolean bool; public static string[] names = new String[3]; public static int point = 0; Add Public sTatic boolean Add (String name) {//judgment legality if (!isok (name)) {return false; }//To determine if there is an if (query (name)! =-1) {System.out.println ("name already exists"); return false; }//Capacity expansion if (point = = Names.length) {addcapacity (); }//Add names[point] = name; point++; return true; }//Remove public static Boolean delete (String name) {//Judge legality if (!isok (name)) {return fals E }//To determine if there is an int index = query (name); if (index = =-1) {System.out.println ("name does not exist"); return false; }//delete for (int i = index, i < point; i++) {Names[i] = names[i + 1]; } point--; return true; }//Modify public static Boolean update (string name, String newName) {if (!isok (name) | |!isok (newName)) { return false; }//To determine if there isint index = query (name); if (index = =-1) {System.out.println ("name does not exist"); return false; } if (query (newName)! =-1) {System.out.println ("name already exists"); return false; }//Modify names[index] = NewName; return true; }//query public static int query (String name) {for (int i = 0; i < point; i++) {if (names[i].e Quals (name)) {return i; }} return-1; }//Judge legitimacy public static Boolean isOk (String name) {if (Name.length () < 2 | | name.length () > 8) { System.out.println ("Name is not lawful"); return false; } return true; }//expansion public static void Addcapacity () {string[] newnames = new string[names.length * 2]; for (int i = 0; i < names.length; i++) {newnames[i] = names[i]; } names = Newnames; }//print public static void print () {for (int i = 0; i < point; i++) {System.out.println (names[i]); } }}
Import Java.util.scanner;public class Studentmanagementsystem {public static void main (string[] args) {//Do a learning Information management system, currently only supports the management of student information in the form of < name > (increase and deletion), that is, management is only the student's name information Scanner Scanner = new Scanner (system.in); Boolean flage = true; while (flage) {System.out.println ("Select the function you want to operate: \n1-Add \t2-Delete \t3-Modify \t4-query \t5-exit"); int num = Scanner.nextint (); Switch (num) {case 1:SYSTEM.OUT.PRINTLN ("Please enter the name you want to add:"); Name = Scanner.next (); BOOL = Add (name); if (bool) {SYSTEM.OUT.PRINTLN ("add success"); } else {System.out.println ("Add failed"); } break; Case 2:SYSTEM.OUT.PRINTLN ("Please enter the name you want to delete:"); String name = Scanner.next (); bool = delete (name); if (bool) {System.out.println ("delete succeeded"); } else { System.out.println ("delete failed"); } break; Case 3:SYSTEM.OUT.PRINTLN ("Please enter a name to be modified:"); Name = Scanner.next (); System.out.println ("Please enter the modified name"); String newName = Scanner.next (); BOOL = Update (name, newName); if (bool) {SYSTEM.OUT.PRINTLN ("modified successfully"); } else {System.out.println ("failed to modify"); } break; Case 4:print (); Break Case 5:system.out.println ("Welcome to the next use, Goodbye!") "); Flage = false; Break DEFAULT:SYSTEM.OUT.PRINTLN ("Select Error, please re-enter"); Break }} scanner.close (); } public static String name; public static Boolean bool; public static string[] names = new String[3]; public static int point = 0; Add Public sTatic boolean Add (String name) {//judgment legality if (!isok (name)) {return false; }//To determine if there is an if (query (name)! =-1) {System.out.println ("name already exists"); return false; }//Capacity expansion if (point = = Names.length) {addcapacity (); }//Add names[point] = name; point++; return true; }//Remove public static Boolean delete (String name) {//Judge legality if (!isok (name)) {return fals E }//To determine if there is an int index = query (name); if (index = =-1) {System.out.println ("name does not exist"); return false; }//delete for (int i = index, i < point; i++) {Names[i] = names[i + 1]; } point--; return true; }//Modify public static Boolean update (string name, String newName) {if (!isok (name) | |!isok (newName)) { return false; }//To determine if there isint index = query (name); if (index = =-1) {System.out.println ("name does not exist"); return false; } if (query (newName)! =-1) {System.out.println ("name already exists"); return false; }//Modify names[index] = NewName; return true; }//query public static int query (String name) {for (int i = 0; i < point; i++) {if (names[i].e Quals (name)) {return i; }} return-1; }//Judge legitimacy public static Boolean isOk (String name) {if (Name.length () < 2 | | name.length () > 8) { System.out.println ("Name is not lawful"); return false; } return true; }//expansion public static void Addcapacity () {string[] newnames = new string[names.length * 2]; for (int i = 0; i < names.length; i++) {newnames[i] = names[i]; } names = Newnames; }//print public static void print () {for (int i = 0; i < point; i++) {System.out.println (names[i]); } }}