shenxian32 2021-11-03 19:22 采纳率: 90.5%
浏览 16
已结题

关于#java#的问题:第一个类(TeamService)中大概62行判断team[i]和Architect,Designer是否为同一类型为什么会报错该如何解决呢

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是否为同一类型为什么会报错该如何解决呢

  • 写回答

1条回答 默认 最新

  • BCS-点心 2021-11-04 11:01
    关注

    把错误发出来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月12日
  • 已采纳回答 11月4日
  • 创建了问题 11月3日

悬赏问题

  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真