package viewservice;
import domain.Architect;
import domain.Designer;
import domain.Employee;
import domain.Programmer;
import domain.Status;
/**
* @author Administrator
*
*/
public class TeamService {
private static int counter=1;//给memberId赋值使用
final int MAX_MEMBER=5;//限制开发团队的人数
private Programmer[]team=new Programmer[5];
private int total;//记录开发团队的实际人数
public TeamService() {
super();
}
/*
* 获取开发团队的成员
*/
public Programmer[] getTeam(){
Programmer[]team=new Programmer[total];
for(int i=0;i<team.length;++i) {
team[i]=this.team[i];
}
return team;
}
/**
* @return
* @throws TeamException
*/
public void addMember(Employee e) throws TeamException {
//成员已满,无法添加
if(total>=MAX_MEMBER) {
throw new TeamException("成员已满无法添加");
}
// 该成员不是开发人员,无法添加
if(!(e instanceof Programmer)) {
throw new TeamException("该成员不是开发人员无法添加");
}
//该成员已在开发团队中
if(isExist(e)){
throw new TeamException("该成员已经在团队中了");
}
//该成员已经在其他工作团队中
Programmer p=(Programmer)e;
if(p.getStatus().getName().equals("BUSY")) {
throw new TeamException("该成员已经在其他团队中了");
}else if("VOCATION".equals(p.getStatus().getName())) {
throw new TeamException("该员工正在休假");
}
//团队中只能有一名架构师
//团队中至多有两名设计师
//团队中至多只能有三名程序员
//获取team中已有成员中架构师设计师,程序员的人数
int numofArch=0,numofDes=0,nuOfPro=0;
for(int i=0;i<total;++i) {
if(team[i] instanceof Architect) {
numofArch++;
}else if(team[i] instanceof Designer) {
numofDes++;
}else if(team[i] instanceof Programmer) {
nuOfPro++;
}
}
if(p instanceof Architect) {
if(numofArch>=1) {
throw new TeamException("只能有一个架构师");
}
}
if(p instanceof Designer) {
if( numofDes>=2) {
throw new TeamException("只能有两个设计师");
}
}
if(p instanceof Programmer) {
if( nuOfPro>=3) {
throw new TeamException("只能有三个程序员");
}
}
//将p添加到现有的team中
team[total++]=p;
//p的属性赋值
p.setStatus(Status.BUSY);
p.setMemberId(counter++);
}
/**判断指定员工是不是在团队中
* @param e
* @return
*/
private boolean isExist(Employee e) {
// TODO Auto-generated method stub
for(int i=0;i<total;++i) {
if(team[i].getId()==e.getId()) {
return true;
}
}
return false;
}
public void removeMember(int memberId) {
}
}
package domain;
public class Programmer extends Employee {
public Programmer(int id, String name, int age, double salary) {
super(id, name, age, salary);
}
private int memberId;//开发团队中的id
private Status status;
private Equipment equipment;
public Programmer(int id, String name, int age, double salary, Equipment equipment) {
super(id, name, age, salary);
this.equipment = equipment;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public Equipment getEquipment() {
return equipment;
}
public void setEquipment(Equipment equipment) {
this.equipment = equipment;
}
}
package domain;
public class Designer extends Employee {
double bonus;//奖金
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public Designer(int id, String name, int age, double salary, double bonus) {
super(id, name, age, salary);
this.bonus = bonus;
}
public Designer(int id, String name, int age, double salary) {
super(id, name, age, salary);
}
}
package domain;
public class Employee {
private int id;
private String name;
private int age;
private double salary;
public Employee(int id, String name, int age, double salary) {
super();
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + "]";
}
}
package domain;
public class Architect extends Employee {
int stock;//公司奖励的股票数量
public Architect(int id, String name, int age, double salary, int stock) {
super(id, name, age, salary);
this.stock = stock;
}
public Architect(int id, String name, int age, double salary) {
super(id, name, age, salary);
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
}
第一个类(TeamService)中大概62行判断team[i]和Architect,Designer是否为同一类型为什么会报错该如何解决呢