Work with the staff system by using the collection to complete

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.