package com.Emp;java
import java.io.*;
import java.util.*;this
public class ManageEmp {rem
/**
* @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);
}
}
}
}get
class EmpManage{
private ArrayList al=null;
public EmpManage(){
al=new ArrayList();
}
public void addEmp(Emp emp){
al.add(emp);
}
public void showInfo(String empNo){it
//遍歷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());io
}
}
}
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
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;
}
}import