0
点赞
收藏
分享

微信扫一扫

项目团队人员管理Java编程

雪域迷影 2022-01-04 阅读 85

1、问题一:代码运行出错

    /*
     * 增加小组成员
     */
    public void addMember(Employee e) throws TeamException{
        if (total >= MAX_MEMBER){
            throw new TeamException("成员已满,无法添加");
        }
        if (!(e instanceof Programmer)){
            throw new TeamException("该成员不是开发人员,无法添加");
        }

        Programmer p = (Programmer) e;
        if (isExist(p)){
            throw new TeamException("该员工已在本团队中");
        }
        if(p.getStatus().getNAME().equals("BUSY")) {
            throw new TeamException("该员工已是某团队成员");
        }else if(p.getStatus().getNAME().equals("VOCATION")) {
            throw new TeamException("该员正在休假,无法添加");
        }

        //计算出当前团队程序员、设计师、架构师的人数
        int numOfPro = 0, numOfDes = 0, numOfArch = 0;
        for (int i =0;i < total;i++){
            if (team[i] instanceof Programmer){
                numOfPro++;
            }else if (team[i] instanceof Designer){
                numOfDes++;
            }else if (team[i] instanceof Architect){
                numOfArch++;
            }
        }
        //判断当前要添加的p是否超出了各个工种所要求的人数
        if (p instanceof Architect && numOfArch >= 1){
            throw new TeamException("团队中至多只能有一名架构师");
        }else if (p instanceof Designer && numOfDes >= 2){
            throw new TeamException("团队中至多只能有两名设计师");
        }else if (p instanceof Programmer && numOfPro >= 3){
            throw new TeamException("团队中至多只能有三名程序员");
        }

        //无上述异常,则执行下述添加语句
        p.setStatus(Status.BUSY);
        p.setMemberId(counter++);
        team[total++] = p;
    }

    //判断该成员是否已在团队
    private boolean isExist(Programmer p){
        for (int i = 0;i < total;i++){
            if (team[i].getId() == p.getId()){
                return true;
            }
        }
        return false;
    }

在添加小组成员时,程序跑到判断是否“空闲”时,获取不到状态null;

问题原因:未在初始状态就给各个人员赋初始状态。

 private Status status = Status.FREE;    //实现将所有人状态置为free,否则默认null
举报

相关推荐

0 条评论