标签:
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!"); } } } }
标签:
原文地址:http://www.cnblogs.com/xuhuaiqu/p/4445294.html