JavaSE進(jìn)階
2、編寫異常類TeamException
用于封裝整個項目中的異常,例如
添加員工到開發(fā)團(tuán)隊時會遇到如下失敗情況
例如從團(tuán)隊中刪除員工會遇到如下失敗情況
- 找不到該成員,無法刪除
package com.atguigu.service;
public class TeamException extends Exception {
??? public TeamException() { ??? super(); ??? }
??? public TeamException(String message) { ??????? super(message); ??? } }
|
3、編寫業(yè)務(wù)類NameListService
service模塊為實(shí)體對象(Employee及其子類如程序員等)的管理模塊, NameListService和TeamService類分別用各自的數(shù)組來管理公司員工和開發(fā)團(tuán)隊成員對象
package com.atguigu.service;
import com.atguigu.bean.Employee;
public class NameListService { ??? private Employee[] employees;
??? public Employee[] getAllEmployees() { ??????? return employees; ??? }
??? public Employee getEmployee(int id) throws TeamException { ??????? for (Employee e : employees) { ??????????? if (e.getId() == id) ??????????????? return e; ??????? } ??????? throw new TeamException("該員工不存在"); ??? } }
|