Employee management system features include:
1, add new employees;
2. Display the information of an employee;
3, display all employee information;
4, revise employee salary;
5. Delete an employee.
The code is as follows:
1 Packagetest;2 ImportJava.io.*;3 ImportJava.util.*;4 Public classManagesystem {5 6 Public Static voidMain (string[] args)throwsioexception{7 //TODO auto-generated Method Stub8 9HashMap hm=NewHashMap ();Ten while(true) One { ASystem.out.println ("Select the action you want to take:"); -System.out.println ("1 means Add new employee"); -System.out.println ("2 indicates that an employee information is displayed"); theSystem.out.println ("3 means show all employee information"); -System.out.println ("4 means modified employee salary"); -System.out.println ("5 means delete an employee"); -System.out.println ("6 means exit program"); +InputStreamReader isr=NewInputStreamReader (system.in); -BufferedReader br=NewBufferedReader (ISR); + intInputnum = 0; A Try at { -inputnum=Integer.parseint (Br.readline ()); -}Catch(Exception e) - { -System.out.println ("Please enter integer 1~6"); - e.printstacktrace (); in } - to Switch(Inputnum) + { - Case1: theAddclerk addclerk=NewAddclerk (); * Addclerk.add (HM); $ Break;Panax Notoginseng Case2: -Showinfo showinfo=Newshowinfo (); the Showinfo.show (HM); + Break; A Case3: the + Break; - Case4: $ $ Break; - Case5: - the Break; - Case6:WuyiSystem.exit (0); the Break; - } Wu } - } About $ } - - classAddclerk - { A Public voidAdd (HashMap HM)throwsIOException + { theSystem.out.println ("Please enter the employee number to be added:"); -InputStreamReader isr=NewInputStreamReader (system.in); $BufferedReader br=NewBufferedReader (ISR); theClerk clerk=Newclerk (); theString temp=br.readline (); the Clerk.setclerkno (temp); theSystem.out.println ("Please enter the name of the employee you want to add:"); - Clerk.setname (Br.readline ()); inSystem.out.println ("Please enter the employee salary to be added:"); the clerk.setsalary (Integer.parseint (Br.readline ())); the Hm.put (Temp,clerk); AboutSystem.out.println ("Add success: \ n" the+ ((Clerk) (Hm.get (temp))). Getclerkno () + "," the+ ((Clerk) (Hm.get (temp))). GetName () + "," the+ ((Clerk) (Hm.get (temp))). Getsalary () + "\ n"); + } - } the Bayi classShowinfo the { the Public voidShow (HashMap HM)throwsIOException - { -System.out.println ("Please enter the employee number to find:"); theInputStreamReader isr=NewInputStreamReader (system.in); theBufferedReader br=NewBufferedReader (ISR); theString temp=br.readline (); the if(Hm.containskey (temp)) - { theSYSTEM.OUT.PRINTLN ("The employee's information is:" the+ ((Clerk) (Hm.get (temp))). Getclerkno () + "," the+ ((Clerk) (Hm.get (temp))). GetName () + ","94+( (Clerk) (Hm.get (temp))). Getsalary ()); the}Else the { theSystem.out.println ("No staff! ");98 } About System.out.println (); - }101 }102 103 classClerk104 { the PrivateString Clerkno;106 PrivateString name;107 Private intsalary;108 109 PublicString Getclerkno () { the returnClerkno;111 } the Public voidSetclerkno (String clerkno) {113 This. Clerkno =Clerkno; the } the PublicString GetName () { the returnname;117 }118 Public voidsetName (String name) {119 This. Name =name; - }121 Public intgetsalary () {122 returnsalary;123 }124 Public voidSetsalary (intsalary) { the This. Salary =salary;126 }127}
The results of the demo run are as follows:
1 Please select the action you want to take:2 1 means adding a new employee3 2 indicates that an employee information is displayed4 3 indicates all employee information is displayed5 4 means to revise employee salary6 5 means to delete an employee7 6 means exiting the program819 Please enter the employee number to be added:Ten s001 One Please enter the name of the employee you want to add: A Farong - Please enter the employee salary to be added: -1200 the Add success: -S001, Farong, 1200 - - Please select the action you want to take: + 1 means adding a new employee - 2 indicates that an employee information is displayed + 3 indicates all employee information is displayed A 4 means to revise employee salary at 5 means to delete an employee - 6 means exiting the program -2 - Please enter the employee number to find: - s001 -The employee's information is: s001, Farong, 1200 in - Please select the action you want to take: to 1 means adding a new employee + 2 indicates that an employee information is displayed - 3 indicates all employee information is displayed the 4 means to revise employee salary * 5 means to delete an employee $6 means exiting the program
Java Employee Management System exercises (not to be continued)