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("不存在此员工");
}
}
看报错,鼠标点到那个蓝色的字上面,56行,报错说数组越界了,检查一下你的数组
case代码块结束要加break的啊
另外case代码块最好用大括号括起来
单步执行调试一下,每执行一次查看下i值的变化。