package com.Emp;
import java.io.*;
import java.util.*;
public class ManageEmp {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
EmpManage em=new EmpManage();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("雇员管理(1:添加一个雇员。2:查找一个雇员。3:修改一个雇员的工资。4:删除一个雇员.5:推出系统");
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"))
{
System.out.println("请输入编号:");
String empNo=br.readLine();
System.out.println("请输入更改工作:");
float newSal=Float.parseFloat(br.readLine());
em.updateSal(empNo, newSal);
}
else if(operType.equals("4"))
{
System.out.println("请输入编号:");
String empNo=br.readLine();
em.delEmp(empNo);
}
else if(operType.equals("5"))
{
System.exit(-1);
}
}
}
}
class EmpManage{
private ArrayList al=null;
public EmpManage(){
al=new ArrayList();
}
public void addEmp(Emp emp){
al.add(emp);
}
public void showInfo(String empNo){
//遍历arraylsit
for(int i=0;i<al.size();i++){
Emp emp=(Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
System.out.println("员工信息是:");
System.out.println("编号:"+empNo);
System.out.println("员工信息是:"+emp.getName());
System.out.println("员工工资是:"+emp.getSal());
}
}
}
public void updateSal(String empNo,float newSal){
for(int i=0;i<al.size();i++)
{
Emp emp=(Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
emp.setSal(newSal);
}
}
}
public void delEmp(String empNo)
{
for(int i=0;i<al.size();i++)
{
Emp emp=(Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
al.remove(i);
//al.remove(emp);
}
}
}
}
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;
}
}