java集合-- arraylist小員工項目

來源:互聯網
上載者:User

標籤:

import java.io.*;import java.util.ArrayList;public class Emexe {        public static void main(String[] args) throws IOException {                EmpManage em=new EmpManage();                BufferedReader br=new  BufferedReader(new InputStreamReader(System.in));        while(true){            System.out.println("**********管理菜單************");            System.out.println("1、添加僱員");            System.out.println("2、尋找僱員");            System.out.println("3、修改僱員");            System.out.println("4、刪除僱員");            System.out.println("******************************");            System.out.println("請輸入數字1-4選擇:");                        String operType=br.readLine();            if(operType.equals("1")){                System.out.println("請輸入僱員編號");                String empNo=br.readLine();                System.out.println("請輸入僱員名字");                String name=br.readLine();                System.out.println("請輸入僱員薪水");                float sal=Float.parseFloat(br.readLine());                                Emp emp=new Emp(empNo,name,sal);                em.addEmp(emp);            }            else if(operType.equals("2")){                System.out.println("請輸入僱員編號");                String empNo=br.readLine();                em.showInfo(empNo);            }            else if(operType.equals("3")){                            }            else if(operType.equals("4")){                }        }            }}class Emp{    private String empNo;    private String name;    private float sal;        public Emp(String empNo,String name,float sal){        this.empNo=empNo;        this.name=name;        this.sal=sal;    }    public String getEmpNo() {        return empNo;    }    public void setEmpNo(String empNo) {        this.empNo = empNo;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public float getSal() {        return sal;    }    public void setSal(float sal) {        this.sal = sal;    }        }class EmpManage{    private ArrayList a1=null;        public EmpManage(){        a1=new ArrayList();    }    public void addEmp(Emp emp){        a1.add(emp);    }    public void showInfo(String empNo){        //遍曆整個ArrayList        for(int i=0;i<a1.size();i++)        {            //取出Emp            Emp emp=(Emp) a1.get(i);            if(emp.getEmpNo().equals(empNo)){                System.out.println("該員工編號"+empNo+"姓名"+emp.getName()+"薪水"+emp.getSal());                            }        }    }    public void update(String empNo,float newSal){        for(int i=0;i<a1.size();i++){            Emp emp=(Emp) a1.get(i);            if(emp.getEmpNo().equals(empNo)){                emp.setSal(newSal);                System.out.println("success!");            }        }    }    public void delEmp(String empNo){        for(int i=0;i<a1.size();i++){            Emp emp=(Emp) a1.get(i);            if(emp.getEmpNo().equals(empNo)){                a1.remove(i);                System.out.println("success!");            }        }    }}

 

java集合-- arraylist小員工項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.