| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:不知道哪里错了,求指教
只看楼主 加入收藏
hsjjgm
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:106
专家分:189
注 册:2013-4-27
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:3 
不知道哪里错了,求指教
为什么我的查找,修改和删除功能都没有效果?
package EMP;
import java.util.*;
import *;
public class Emp
{

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception
    {
        // TODO Auto-generated method stub
        //创建EmpManage对象
        EmpManage emp = 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("5: 删除员工");
            System.out.println("6: 最高和平均工资");
            
            //定义对操作流的操作方式
            //以行为单位操作
            String operType = br.readLine();
            
            if(operType.equals("1"))
            {
                System.out.println("请输入新员工ID");
                String ID = br.readLine();
                System.out.println("请输入新员工姓名");
                String name = br.readLine();
                System.out.println("请输入新员工工资");
                float sal = Float.parseFloat(br.readLine());
               
                EmpMember emp1 = new EmpMember(ID,name,sal);
                emp.addEmp(emp1);
            }
            else if(operType.equals("2"))
            {
                System.out.println("请输入要查找的员工工号");
                String ID = br.readLine();
                emp.trackInfo(ID);
            }
            else if(operType.equals("3"))
            {
                emp.traverseMember();
            }
            else if(operType.equals("4"))
            {
                System.out.println("请输入要修改的员工工号");
                String ID = br.readLine();
                System.out.println("请输入要修改的工资");
                float newsal = Float.parseFloat(br.readLine());
                emp.modifySal(ID, newsal);
            }
            else if(operType.equals("5"))
            {
                System.out.println("请输入要删除员工的工号");
                String ID = br.readLine();
               
                emp.DelMember(ID);
            }
            else if(operType.equals("6"))
            {
                emp.stasal();
            }
        }
    }
}

class EmpMember
{
    //属性:姓名,工号,工资
    private String name;
    private String ID;
    private float sal;
    //构造方法
    public EmpMember(String name, String ID, float sal)
    {
        this.name = name;
        this.ID = ID;
        this.sal = sal;
    }
   
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getID() {
        return ID;
    }
    public void setID(String iD) {
        ID = iD;
    }
    public float getSal() {
        return sal;
    }
    public void setSal(float sal) {
        this.sal = sal;
    }
}

class EmpManage
{
    //创建一个集合
    ArrayList al = new ArrayList();
    //EmpMember emp = null;
   
    //添加员工信息
    public void addEmp(EmpMember e)
    {
        al.add(e);
    }
   
    //根据工号查找员工
    public void trackInfo(String ID)
    {
        for(int i = 0; i < al.size(); i++)
        {
            EmpMember emp = (EmpMember) al.get(i);
            if(emp.getID().equals(ID))
            {
                System.out.println("该员工信息如下");
                System.out.println("工号="+ID);
                System.out.println("姓名="+emp.getName());
                System.out.println("工资="+emp.getSal());
            }
        }
    }
   
    //遍历所有员工
    public void traverseMember()
    {
        for(int i = 0; i<al.size();i++)
        {
            EmpMember emp = (EmpMember) al.get(i);
            System.out.println("第"+(i+1)+"员工的信息如下");
            System.out.println("工号="+emp.getID());
            System.out.println("姓名="+emp.getName());
            System.out.println("工资="+emp.getSal());
        }
    }
   
    //修改某个员工的工资
    public void modifySal(String ID, float newsal)
    {
        for(int i = 0; i < al.size(); i++)
        {
            EmpMember emp =(EmpMember)al.get(i);
            if(emp.getID().equals(ID))
            {
                emp.setSal(newsal);
            }
        }
    }

//删除某个员工
public void DelMember(String ID)
{
    for(int i = 0; i < al.size();i++)
    {
        EmpMember emp = (EmpMember)al.get(i);
        if(emp.getID().equals(ID))
        {
            al.remove(i);
        }
    }
}

//统计平均工资和最高工资
public void stasal()
{
    float max = 0,average = 0,sum = 0;
    int tag;
    for(int i = 0; i < al.size();i++)
    {
        EmpMember emp = (EmpMember)al.get(i);
        //求最值
        if(emp.getSal() > max)
        {
            max = emp.getSal();
            tag = i;
        }
        //求均值
        sum = sum+emp.getSal();
    }
    average = sum/al.size();
    System.out.println("最高工资为"+max);
    System.out.println("平均工资为"+average);
}
}



搜索更多相关主题的帖子: static package public import 
2013-05-25 14:16
ren829
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:15
帖 子:255
专家分:1174
注 册:2006-3-11
收藏
得分:20 
EmpMember emp1 = new EmpMember(ID,name,sal);
  public EmpMember(String name, String ID, float sal)


我擦,你这问题可真够坑爹的,害的我看了好半天,自己发现问题了吧?

[ 本帖最后由 ren829 于 2013-5-25 15:04 编辑 ]
2013-05-25 14:35
hsjjgm
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:106
专家分:189
注 册:2013-4-27
收藏
得分:0 
感谢斑竹
2013-05-25 15:34
快速回复:不知道哪里错了,求指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108141 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved