KRNNNS 2022-07-28 13:01 采纳率: 100%
浏览 376
已结题

java入门 找不到局部变量

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图

package service;
import domain.;
import domain.Equipment;
import static service.Data.EQUIPMENTS;
import static service.Data.
;

/**

  • @description: 负责将Data中的数据封装到Employee[]数组中,同时提供相关操作Employee[]的方法

  • /
    public class NameListService {
    private Employee[] employees;

    public NameListService(){

              employees=new Employee[Data.EMPLOYEES.length];
    
              for (int i = 0;i<employees.length;i++){
                  //Architect :  13, id, name, age, salary, bonus, stock
                  int type=Integer.parseInt(Data.EMPLOYEES[i][0]);
                  int id=Integer.parseInt(EMPLOYEES[i][1]);
                  String name=EMPLOYEES[i][2];
                  int age=Integer.parseInt(Data.EMPLOYEES[i][3]);
                  int salary=Integer.parseInt(Data.EMPLOYEES[i][4]);
                  Equipment eq;
                  double bouns;
                  int stock;
                  switch (type){
                      case EMPLOYEE:
                          employees[i]=new Employee( id, name, age, salary);
    
                      case PROGRAMMER:
                          eq=createquipment(i);
                          employees[i]=new Programmer(id, name, age, salary,eq);
    
                      case DESIGNER:
                          eq=createquipment(i);
                           bouns=Double.parseDouble(EQUIPMENTS[i][5]);
                          employees[i]=new Designer( id, name, age, salary,eq,bouns);
    
                      case ARCHITECT:
                          eq=createquipment(i);
                          bouns=Double.parseDouble(EQUIPMENTS[i][5]);
                          stock=Integer.parseInt(EQUIPMENTS[i][6]);
                          employees[i]=new Architect( id, name, age, salary,eq,bouns,stock);
                  }
              }
    

    }

private Equipment createquipment(int index){
    int type=Integer.parseInt(EQUIPMENTS[index][0]);
    switch (type){
        //        {"22", "联想T4", "6000"},
        //        {"21", "戴尔", "NEC17寸"},
        //        {"21", "戴尔", "三星 17寸"},
        //        {"23", "佳能 2900", "激光"},
        case PC:
            return new PC(EQUIPMENTS[index][1], EQUIPMENTS[index][2]);
        case NOTEBOOK:
            int price=Integer.parseInt(EQUIPMENTS[index][2]);
            return new NoteBook(EQUIPMENTS[index][1], price);
        case PRINTER:
            return new Printer(EQUIPMENTS[index][1],EQUIPMENTS[index][2]);
    }
    return null;
}
//获取所有员工
public Employee[]  getAllEmployees(){
    return employees;
}
public Employee  getEmployees (int id)throws TeamException{
    for (int i=0;i<employees.length;i++){
        if(employees[i].getId()==id)
            return employees[i];
    }
    throw new TeamException("不存在此员工");
}

}

运行结果及报错内容

img

  • 写回答

3条回答 默认 最新

  • 林晓风 2022-07-28 13:33
    关注

    看报错,鼠标点到那个蓝色的字上面,56行,报错说数组越界了,检查一下你的数组

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 8月5日
  • 已采纳回答 7月28日
  • 修改了问题 7月28日
  • 创建了问题 7月28日

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上