One: Requirements
The information stored includes: ID, name, phone number, address, marital status, birthday.
Function: The staff can make additions and deletions to check and change.
Ideas:
1) A class with the Main method
2) An employee's entity class employee;
3) A class dbcenter of adding and deleting and changing;
1) Code: Class with Main method
PackageCom.niit.book;ImportJava.util.Scanner;ImportCom.niit.dbcenter.DBcenter;ImportCom.niit.entity.Employee;/** * @author: Annie * @date: May 15, 2016 * @description: Run the program, call and delete the change method*/ Public classEmployeemain { Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); System.out.println ("Please enter the number of employees to be deposited:"); intNumber =In.nextint (); Employee [] Employee=NewEmployee[number]; Dbcenter DB=NewDbcenter (); while(true) {System.out.println ("Please enter the action to be taken"); System.out.println ("------Menu-------"); System.out.println ("1.add Data"); System.out.println ("2.Update Data"); System.out.println ("3.Display Data"); System.out.println ("4:delete Date"); System.out.println ("5.Exit"); System.out.println ("---------"); intnum =In.nextint (); Switch(num) { Case1: Db.adddate (employee); Break; Case2: Db.updatedate (employee); Break; Case3: Db.displaydate (employee); Break; Case4: Db. Deletedate (employee); Break; Case5: System.exit (0); Break; } } }}
2) Code: entity class
/** * */ Packagecom.niit.entity;/** * @author: Annie * @date: May 15, 2016 * @description: basic information for Employees*/ Public classEmployee {Private intID; PrivateString name; PrivateString Tel; PrivateString addr; PrivateString birthday; PrivateString MaritalStatus; Public intGetID () {returnID; } Public voidSetID (intID) { This. ID =ID; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } PublicString Gettel () {returnTel; } Public voidSettel (String tel) { This. Tel =Tel; } PublicString getaddr () {returnaddr; } Public voidsetaddr (String addr) { This. addr =addr; } PublicString Getbirthday () {returnbirthday; } Public voidsetbirthday (String birthday) { This. Birthday =birthday; } PublicString Getmaritalstatus () {returnMaritalStatus; } Public voidsetmaritalstatus (String maritalstatus) { This. MaritalStatus =MaritalStatus; } Publicstring toString () {string msg= This. id+ "\ T" + This. name+ "\ T" + This. tel+ "\t\t" + This. addr+ "\ T" + This. birthday+ "\ T" + This. MaritalStatus; returnmsg; }}
3) Code Dbcenter
/** * */ PackageCom.niit.dbcenter;ImportJava.util.Scanner;ImportCom.niit.entity.Employee;/** * @author: Annie * @date: May 15, 2016 * @description: Change and delete Employees*/ Public classDbcenter {Scanner in=NewScanner (system.in); String msg= "number" + "\ T" + "name" + "\ T" + "phone number" + "\t\t" + "address" + "\ T" + "birthday" + "\ T" + "marital status"; /*Determine if there is an empty position in the array, if not, do not install, if there is, then install **/ Public intSetindext (Employee [] arr) { for(inti = 0; i < arr.length; i++) { if(arr[i]==NULL){ returni; } } return999; } /*for outputting student information, i.e. refreshing information*/ Public voidprint (Employee [] arr) {System.out.println (msg); for(inti = 0; i < arr.length; i++) { //determine if there is if(arr[i]!=NULL) {System.out.println (arr[i]); } } } /*used to determine if an employee exists*/ Public BooleanExsit (intId,employee arr) { if(arr!=NULL) { if(Arr.getid () = =ID) { return true; }Else{ return false; } } return false; } /*Increase Employee*/ Public voidadddate (employee[] arr) {System.out.println ("Please enter the employee's name:"); String name=In.next (); System.out.println ("Please enter the employee's phone number:"); String Tel=In.next (); System.out.println ("Please enter the employee's address:"); String Addr=In.next (); System.out.println ("Please enter the employee's birthday:"); String Birthday=In.next (); System.out.println ("Please enter the marital status of the employee"); String MaritalStatus=In.next (); Employee Employee=NewEmployee (); Employee.setname (name); Employee.setaddr (addr); Employee.setbirthday (birthday); Employee.settel (tel); Employee.setmaritalstatus (MaritalStatus); inti = This. Setindext (arr); Employee.setid (i); if(i==999) {System.out.println ("The number of people has reached the maximum and can no longer be added."); }Else{Arr[i]=employee; This. Print (arr); } } /*Delete an employee*/ Public voiddeletedate (employee[] arr) {System.out.println ("Please enter the ID of the employee you want to delete:"); intID =In.nextint (); for(inti = 0; i < arr.length; i++) { if( This. Exsit (ID, arr[i])) {Arr[i]=NULL; System.out.println ("---Student information deleted successfully---"); This. Print (arr); return; }} System.out.println ("The student you have specified does not exist."); } /*Query Employee: Find by ID*/ Public voiddisplaydate (employee[] arr) {System.out.println ("Please enter the number of the employee to be queried:"); intID =In.nextint (); for(inti = 0; i < arr.length; i++) { if( This. Exsit (ID, arr[i])) { This. Print (arr); return; }} System.out.println ("This student does not exist."); } /*Modify Employee: Update by ID*/ Public voidupdatedate (Employee [] arr) {System.out.println ("Please enter the employee ID to be updated"); intID =In.nextint (); for(inti = 0; i < arr.length; i++) { if( This. Exsit (ID, arr[i])) {System.out.println ("Please enter" +arr[i].getname () + "Modified name:"); String name=In.next (); System.out.println ("Please enter" +arr[i].getname () + "modified phone number:"); String Tel=In.next (); System.out.println ("Please enter" +arr[i].getname () + "modified address:"); String Addr=In.next (); System.out.println ("Please enter" +arr[i].getname () + "Modified Birthday:"); String Birthday=In.next (); System.out.println ("Please enter" +arr[i].getname () + "Modified marital status"); String MaritalStatus=In.next (); Arr[i].setname (name); Arr[i].setaddr (addr); Arr[i].setbirthday (birthday); Arr[i].settel (tel); Arr[i].setmaritalstatus (MaritalStatus); System.out.println ("----Update successfully----"); This. Print (arr); } } }}
Operation Result:
Increase the running result of employee information:
Update operation result: The rest runs on its own
A management system for storing 100 employees ' information in an array