组建团队类
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;
}
if (i==total)
{
throw new teamException("找不到指定元素");
}
for (int j=i+1;j<total;j++)
{
team[j-1]=team[j];
}
team[--total]=null;
}
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;
int stock;
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("找不到指定员工");
}
}