Java Collection--ArrayList small staff project

Source: Internet
Author: User

ImportJava.io.*;Importjava.util.ArrayList; Public classEmexe { Public Static voidMain (string[] args)throwsIOException {empmanage em=NewEmpmanage (); BufferedReader BR=NewBufferedReader (NewInputStreamReader (system.in));  while(true) {System.out.println ("********** Management menu ************"); System.out.println ("1, add employee"); System.out.println ("2, find Employees"); System.out.println ("3. Modification of employees"); System.out.println ("4, delete employees"); System.out.println ("******************************"); System.out.println ("Please enter the number 1-4 select:"); String Opertype=Br.readline (); if(Opertype.equals ("1") {System.out.println ("Please enter employee number"); String EmpNo=Br.readline (); System.out.println ("Please enter employee name"); String name=Br.readline (); System.out.println ("Please enter employee 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 employee number"); String EmpNo=Br.readline ();            Em.showinfo (EmpNo); }            Else if(Opertype.equals ("3")){                            }            Else if(Opertype.equals ("4")){                }        }            }}classemp{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; }        }classempmanage{PrivateArrayList a1=NULL;  PublicEmpmanage () {A1=NewArrayList (); }     Public voidaddemp (emp emp) {a1.add (EMP); }     Public voidshowinfo (String empNo) {//traverse the entire ArrayList         for(intI=0;i<a1.size (); i++)        {            //Remove EMPEMP emp=(EMP) a1.get (i); if(Emp.getempno (). Equals (EmpNo)) {System.out.println ("The employee Number" +empno+ "name" +emp.getname () + "salary" +emp.getsal ()); }        }    }     Public voidUpdate (String EmpNo,floatnewsal) {         for(intI=0;i<a1.size (); i++) {EMP emp=(EMP) a1.get (i); if(Emp.getempno (). Equals (EmpNo)) {emp.setsal (newsal); System.out.println ("Success!"); }        }    }     Public voiddelemp (String empNo) { for(intI=0;i<a1.size (); i++) {EMP emp=(EMP) a1.get (i); if(Emp.getempno (). Equals (EmpNo)) {a1.remove (i); System.out.println ("Success!"); }        }    }}

Java Collection--ArrayList small staff project

Related Article

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.