日期:2014-05-20  浏览次数:20678 次

帮帮忙啦……实在不知道怎么改了!谢啦……
import java.util.*;
import java.io.*;
import java.lang.*;
public class Example1 {

/**
* 功能:实现薪资管理
*/
public static void main(String[] args) throws Exception { 
// TODO Auto-generated method stub
Emp em=new Emp();
BufferedReader b=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("请输入您的选择:");
String operType=b.readLine();
if(operType.equals("1"))
{
System.out.println("请输入编号:");
String num=b.readLine();
System.out.println("请输入姓名:");
String name=b.readLine();
System.out.println("请输入工资:");
float earn=Float.parseFloat(b.readLine());
Personal personal=new Personal();
em.addPersonal(personal);

}else if(operType.equals("2"))
{
System.out.println("请输入编号:");
String num=b.readLine();
em.showInfo(num);
}
else if(operType.equals("3"))
{
System.out.println("请输入编号:");
String num=b.readLine();
System.out.println("请输入工资");
float earn=Float.parseFloat(b.readLine());
em.updateEarn(num, earn);
}
else if(operType.equals("4"))

{
System.out.println("请输入编号:");
String num=b.readLine();
em.delepersonal(num);
}
else
{
System.exit(0);
}
  }
}

}

class Emp
{
private ArrayList<Personal> al=null;

//构造
public Emp()
{
al=new ArrayList<Personal>();

}
public void addPersonal(Personal personal)
{
al.add(personal);

}
//显示员工信息
public void showInfo(String num)
{
//遍历整个AllayList
for(int i=0;i<al.size();i++)
{
//取出Personal对象
Personal personal=al.get(i);
//比较编号
if(personal.getNum().equals(num))
{
System.out.println("找到该员工,他的信息为:");
System.out.println("编号="+num);
System.out.println("名字="+personal.getName());
System.out.println("工资="+personal.getEarn());

}

}

}
//修改工资
public void updateEarn(String num,float earn)
{
for(int i=0;i<al.size();i++)
{
Personal personal=(Personal)al.get(i);
if(personal.getNum().equals(num))
{
personal.setEarn(earn);
System.out.println("现在此人的工资为:"+personal.getEarn());
}
}
}
//删除员工
public void delepersonal(String num)
{
for(int i=0;i<al.size();i++)
{
Personal personal=al.get(i);
if(personal.getNum().equals(num))
{
al.remove(i);
}
}
}
}




class Personal
{
private String name;
private String num;
private float earn;
//构造函数
public void Personal(String name,String num,int earn)
{
this.name=name;
this.num=num;
this.earn=earn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public float getEarn() {
return earn;
}
public void setEarn(float earn) {
this.earn = earn;
}


}


------解决方案--------------------