PackageCom.jihe;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;Importjava.util.ArrayList; Public classTest1 { Public Static voidMain (string[] args)throwsIOException {//Create a Empmanage objectEmpmanage em =NewEmpmanage (); BufferedReader BR=NewBufferedReader (NewInputStreamReader (system.in)); //make a simple menu while(true) {System.out.println ("Please select the action you want to take:"); System.out.println ("1: Add an employee"); System.out.println ("2: Find an employee"); System.out.println ("3: Modify an employee"); System.out.println ("4: Delete an employee"); System.out.println ("5: Exit the System"); String Opertype=Br.readline (); if(Opertype.equals ("1") {System.out.println ("Please enter Number"); String EmpNo=Br.readline (); System.out.println ("Please enter a name"); String name=Br.readline (); System.out.println ("Please enter your salary"); floatSal =float.parsefloat (Br.readline ()); EMP EMP=NewEmp (empNo, name, Sal); Em.addemp (EMP); } Else if(Opertype.equals ("2") {System.out.println ("Please enter Number"); String EmpNo=Br.readline (); Em.showinfo (EmpNo); } Else if(Opertype.equals ("3") {System.out.println ("Please enter Number"); String EmpNo=Br.readline (); System.out.println ("Please enter a new salary"); String Sal=Br.readline (); floatNewsal=float.parsefloat (SAL); Em.updatesal (EmpNo, newsal); } Else if(Opertype.equals ("4") {System.out.println ("Please enter Number"); String EmpNo=Br.readline (); Em.delemp (EmpNo); }Else if(Opertype.equals ("5")){ //Exit SystemSystem.exit (0); } } }}//Employee Management ClassclassEmpmanage {PrivateArrayList Al =NULL; //constructor Function PublicEmpmanage () {Al=NewArrayList (); } //Join the Staff Public voidaddemp (emp emp) {al.add (EMP); } //display information about an employee Public voidshowinfo (String empNo) {//traverse the entire ArrayList for(inti = 0; I < al.size (); i++) { //Remove EMP ObjectEMP emp =(EMP) al.get (i); //Compare Numbers if(Emp.getempno (). Equals (EmpNo)) {System.out.println ("The information to find the employee is:"); System.out.println ("Number =" +empNo); System.out.println ("First name =" +emp.getname ()); System.out.println ("Number =" +emp.getsal ()); } } } //Revise salary Public voidUpdatesal (String EmpNo,floatnewsal) { for(inti = 0; I < al.size (); i++) {EMP emp=(EMP) al.get (i); if(Emp.getempno (). Equals (EmpNo)) {//Revise salaryemp.setsal (newsal); } } } //Delete an employee Public voiddelemp (String empNo) { for(inti = 0; I < al.size (); i++) {EMP emp=(EMP) al.get (i); if(Emp.getempno (). Equals (EmpNo)) {//Delete//Al.remove (i);al.remove (EMP); } } }}//Employee ClassclassEMP {//N PrivateString EmpNo; PrivateString name; Private floatSal; PublicEMP (String empNo, string name,floatSal) { This. EmpNo =EmpNo; This. Name =name; This. Sal =Sal; } PublicString Getempno () {returnEmpNo; } Public voidsetempno (String empNo) { This. EmpNo =EmpNo; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public floatgetsal () {returnSal; } Public voidSetsal (floatSal) { This. Sal =Sal; }}
Work with the staff system by using the collection to complete