团队成员调度系统 关键两类

本文介绍了一个团队服务类的实现,包括团队成员的添加、删除、查询等操作,并详细阐述了人员角色限制及状态检查机制,确保团队结构合理与高效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

组建团队类

public class teamService {
    private static int counter=1;
    private final int MAX=5;
    private programmer[] team=new programmer[MAX];
    private int total;
    public teamService()
    {

    }
    public programmer[] getteam( ) {     //无论是否需要传入参数,括号不可少
         programmer[] team=new programmer[total];
         for (int i=0;i<total;i++)
         {
               team[i]=this.team[i];
         }
        return team;
    }
    public void addteam(person exm)throws teamException
    {
        if (total>=MAX)
        {
            throw new teamException("成员已满,无法添加信息");
        }
        if (!(exm instanceof programmer) )
        {
            throw new teamException("非技术人员");
        }
        if (isexit(exm))
        {
            throw new teamException("该成员已经存在");
        }
        programmer localcae=(programmer)exm;
        if ("BUSY".equals(localcae.getStatus().getName()))
        {
            throw new teamException("该成员已加入其中");
        }else if ("VACATION".equals(localcae.getStatus().getName()))
        {
            throw new teamException("该成员度假中");
        }
        int numofpro=0,numofdes=0,numofart=0;
        for(int i=0;i<total;i++)
        {
            if (exm instanceof architect)
                numofart++;
            else if (exm instanceof Designer)
                numofdes++;
            else
                numofpro++;
        }
        if (localcae instanceof architect)
        {
            if (numofart>=1)
                throw new teamException("架构师仅需一名");
        } else if (localcae instanceof Designer)
        {
            if (numofdes>=2)
                throw new teamException("设计师人数达上限");
        }else
        {
            if (numofpro>=3)
                throw  new teamException("程序员人数已达上限");
        }
        localcae.setStatus(Status.BUSY);
        localcae.setMemberid(counter++);
        team[total++]=localcae;

    }

    public void delElement(int memberId) throws teamException {
        int i=0;
        for ( i=0;i<total;i++)
            if (memberId==team[i].getMemberid())
            {
                team[i].setStatus(Status.FREE);
                break;// 退出的同时 截取了i的最后一次值,也就是被删除的位置
            }
        if (i==total)
        {
            throw new teamException("找不到指定元素");
        }


        for (int j=i+1;j<total;j++)
        {
            team[j-1]=team[j];
        }
        team[--total]=null;  // total-1  不同于 total--的效果   后者对total本身减   前者对数值减一

    }


    private boolean isexit(person exm) {
        for (int i=0;i<total;i++)
        {
            if (team[i].getId()==exm.getId())
                return true;

        }
        return false;
    }


}

初始化团队类

public class nameListservice {
   private person[] Emploees;

   public  nameListservice()
   {
       Emploees=new person[Data.emploees.length];
       for (int i=0;i<Data.emploees.length;i++)
       {
                int type=Integer.parseInt(Data.emploees[i][0]);
                int id=Integer.parseInt(Data.emploees[i][1]);
                String name=Data.emploees[i][2];
                int age=Integer.parseInt(Data.emploees[i][3]);
                double salary=Double.parseDouble(Data.emploees[i][4]);
                equipment equip;
                double bonus;     //switch语句中不可出现同名标识符
               int stock;    //若需要重复使用某一个中间存储值,可将其放在switch外面,而后在内部多次赋值,且每次被使用后无需被保存
                switch (type)
                {
                    case Data.EMPLOYEE:
                        Emploees[i]=new person(id,name,age,salary);
                        break;
                    case  Data.PROGRAMMER:
                         equip=creatEquipment(i);
                        Emploees[i]=new programmer(id,name,age,salary,equip);
                        break;
                     case    Data.DESIGNER:
                          equip=creatEquipment(i);
                         bonus=Double.parseDouble(Data.emploees[i][5]);
                         Emploees[i]=new Designer(id,name,age,salary,equip,bonus);
                         break;
                     case    Data.ARCHITECT:
                          equip=creatEquipment(i);
                         bonus=Double.parseDouble(Data.emploees[i][5]);
                         stock=Integer.parseInt(Data.emploees[i][6]);
                         Emploees[i]=new architect(id,name,age,salary,equip,bonus,stock); //名称写错
                         break;
                }


       }




   }

    private equipment creatEquipment(int i) {
        int type=Integer.parseInt(Data.equipments[i][0]);
          switch (type)
          {
              case Data.PC:
                  return new pc(Data.equipments[i][1],Data.equipments[i][2]);

                  case  Data.NOTEBOOK:
                     double price=Double.parseDouble(Data.equipments[i][2]);
                      return new notebook(Data.equipments[i][1],price);

                     case Data.PRINTER:
                         return new printer(Data.equipments[i][1],Data.equipments[i][2]);
          }
          return null;

   }
   public person[] getEmploees()
   {
       return Emploees;
   }

   public person getemploee(int id) throws teamException {

        for (int i=0;i<Emploees.length;i++)
            if (Emploees[i].getId()==id)
            {
                 return Emploees[i];
            }

       throw new teamException("找不到指定员工");
   }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值