開發人員調度軟體 這幾天在學校弄畢設,異常那邊找了個簡單數組l類項目做了一下 只為記錄,好記性不如爛筆頭 有誤請指正 ありがとうございます。 我的公眾號 作者:晨鐘暮鼓c個人微信公眾號:程式猿的月光寶盒 1.首先,項目名字是開發人員調動軟體,基於控制台,需求如下 2.涉及知識點 1. 類的繼承性和多 ...
開發人員調度軟體
這幾天在學校弄畢設,異常那邊找了個簡單數組l類項目做了一下
只為記錄,好記性不如爛筆頭
有誤請指正
ありがとうございます。
我的公眾號
作者:晨鐘暮鼓c個人微信公眾號:程式猿的月光寶盒
1.首先,項目名字是開發人員調動軟體,基於控制台,需求如下
2.涉及知識點
- 類的繼承性和多態性
- 對象的值傳遞、介面
- static和final修飾符
- 特殊類的使用:包裝類、抽象類、內部類
- 異常處理
3.源碼實現
類
Employee.java
package pers.jsc.dispatch.domain;
/**
* @author 金聖聰
* @title: Employee
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/8 23:48
*/
public class Employee {
private int id;
private String name;
private int age;
private double 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;
}
public Employee(int id, String name, int age, double salary) {
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
}
protected String getDetails(){
return id +"\t"+
name +"\t"+
age +"\t\t"+
salary ;
}
@Override
public String toString() {
return getDetails();
}
}
Programmer.java
package pers.jsc.dispatch.domain.domainexte;
import pers.jsc.dispatch.domain.Employee;
import pers.jsc.dispatch.domain.Equipment;
import pers.jsc.dispatch.service.Status;
/**
* @author 金聖聰
* @title: Programmer
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/8 23:50
*/
public class Programmer extends Employee {
/**
* 用來記錄成員加入開發團隊後在團隊中的ID
*/
private int memberId;
/**
* 成員狀態
*/
private Status status = Status.FREE;
private 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;
}
public Programmer(int id, String name, int age, double salary, Equipment equipment) {
super(id, name, age, salary);
this.equipment = equipment;
}
protected String getMemberNumDetails() {
return memberId + "/" + getDetails();
}
public String getDetails4Team() {
return getMemberNumDetails() + "\t程式員\t";
}
@Override
public String toString() {
return getDetails() + "\t程式員\t" + status + "\t\t\t\t\t" + equipment.getDescription();
}
}
Designer.java
package pers.jsc.dispatch.domain.domainexte;
import pers.jsc.dispatch.domain.Equipment;
/**
* @author 金聖聰
* @title: Designer
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/8 23:55
*/
public class Designer extends Programmer {
/**
* 獎金
*/
private 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, Equipment equipment, double bonus) {
super(id, name, age, salary, equipment);
this.bonus = bonus;
}
@Override
public String getDetails4Team() {
return getMemberNumDetails() +
"\t設計師\t" +
bonus;
}
@Override
public String toString() {
return getDetails() + "\t設計師\t" + getStatus() + "\t" +
bonus + "\t\t\t" + getEquipment().getDescription();
}
}
Architect.java
package pers.jsc.dispatch.domain.domainexte;
import pers.jsc.dispatch.domain.Equipment;
/**
* @author 金聖聰
* @title: Architect
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/8 23:58
*/
public class Architect extends Designer {
/**
* 股票數量
*/
private int stock;
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
public Architect(int id, String name, int age, double salary, Equipment equipment, double bonus, int stock) {
super(id, name, age, salary, equipment, bonus);
this.stock = stock;
}
@Override
public String getDetails4Team() {
return getMemberNumDetails() +
"\t架構師\t" +
getBonus() + "\t" +
stock;
}
@Override
public String toString() {
return getDetails() + "\t架構師\t" + getStatus() + "\t" +
getBonus() + "\t" + stock + "\t" + getEquipment().getDescription();
}
}
介面:
Equipment.java
package pers.jsc.dispatch.domain;
/**
* @author 金聖聰
* @title: Equipment
* @projectName TeamDispatchApp
* @description: 設備
* @date 2019/5/8 23:54
*/
public interface Equipment {
String getDescription ();
}
PC.java
package pers.jsc.dispatch.domain.domainimpl;
import pers.jsc.dispatch.domain.Equipment;
/**
* @author 金聖聰
* @title: PC
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 0:01
*/
public class PC implements Equipment {
/**
* 表示機器的型號
*/
private String model;
/**
* 表示顯示器名稱
*/
private String display;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public PC(String model, String display) {
this.model = model;
this.display = display;
}
@Override
public String getDescription() {
return model+"("+display+")";
}
}
Printer.java
package pers.jsc.dispatch.domain.domainimpl;
import pers.jsc.dispatch.domain.Equipment;
/**
* @author 金聖聰
* @title: Printer
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 0:04
*/
public class Printer implements Equipment {
/**
* 機器的名字
*/
private String name;
/**
* 表示機器的類型
*/
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Printer(String name, String type) {
this.name = name;
this.type = type;
}
@Override
public String getDescription() {
return name+"("+type+")";
}
}
NoteBook.java
package pers.jsc.dispatch.domain.domainimpl;
import pers.jsc.dispatch.domain.Equipment;
/**
* @author 金聖聰
* @title: NoteBook
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 0:02
*/
public class NoteBook implements Equipment {
/**
* 表示機器的型號
*/
private String model;
/**
* 價格
*/
private double price;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public NoteBook(String model, double price) {
this.model = model;
this.price = price;
}
@Override
public String getDescription() {
return model+"("+price+")";
}
}
異常類
TeamException.java
package pers.jsc.dispatch.exception;
/**
* @author 金聖聰
* @title: TeamException
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 0:19
*/
public class TeamException extends RuntimeException{
public TeamException() {
}
public TeamException(String message) {
super(message);
}
}
Service
Data.java
package pers.jsc.dispatch.service;
public class Data {
public static final int EMPLOYEE = 10;
public static final int PROGRAMMER = 11;
public static final int DESIGNER = 12;
public static final int ARCHITECT = 13;
public static final int PC = 21;
public static final int NOTEBOOK = 22;
public static final int PRINTER = 23;
/**
* Employee : 10, id, name, age, salary
* Programmer: 11, id, name, age, salary
* Designer : 12, id, name, age, salary, bonus
* Architect : 13, id, name, age, salary, bonus, stock
*/
public static final String[][] EMPLOYEES = {
{"10", "1", "馬雲 ", "22", "3000"},
{"13", "2", "馬化騰", "32", "18000", "15000", "2000"},
{"11", "3", "李彥巨集", "23", "7000"},
{"11", "4", "劉強東", "24", "7300"},
{"12", "5", "雷軍 ", "28", "10000", "5000"},
{"11", "6", "任志強", "22", "6800"},
{"12", "7", "柳傳志", "29", "10800", "5200"},
{"13", "8", "楊元慶", "30", "19800", "15000", "2500"},
{"12", "9", "史玉柱", "26", "9800", "5500"},
{"11", "10", "丁磊 ", "21", "6600"},
{"11", "11", "張朝陽", "25", "7100"},
{"12", "12", "楊致遠", "27", "9600", "4800"}
};
/**
* 如下的EQUIPMENTS數組與上面的EMPLOYEES數組元素一一對應
* PC :21, model, display
* NoteBook:22, model, price
* Printer :23, name, type
*/
public static final String[][] EQUIPMENTS = {
{},
{"22", "聯想T4", "6000"},
{"21", "戴爾", "NEC17寸"},
{"21", "戴爾", "三星 17寸"},
{"23", "佳能 2900", "激光"},
{"21", "華碩", "三星 17寸"},
{"21", "華碩", "三星 17寸"},
{"23", "愛普生20K", "針式"},
{"22", "惠普m6", "5800"},
{"21", "戴爾", "NEC 17寸"},
{"21", "華碩", "三星 17寸"},
{"22", "惠普m6", "5800"}
};
}
NameListService
package pers.jsc.dispatch.service;
import pers.jsc.dispatch.domain.Employee;
import pers.jsc.dispatch.domain.Equipment;
import pers.jsc.dispatch.domain.domainexte.Architect;
import pers.jsc.dispatch.domain.domainexte.Designer;
import pers.jsc.dispatch.domain.domainexte.Programmer;
import pers.jsc.dispatch.domain.domainimpl.NoteBook;
import pers.jsc.dispatch.domain.domainimpl.PC;
import pers.jsc.dispatch.domain.domainimpl.Printer;
import pers.jsc.dispatch.exception.TeamException;
/**
* @author 金聖聰
* @title: NameListService
* @projectName TeamDispatchApp
* @description: 負責將Data中的數據封裝到Employee[]數組中,同時提供相關操作Employee[]的方法。
* @date 2019/5/9 0:17
*/
public class NameListService {
private Employee[] employees;
public Employee[] getEmployees() {
return employees;
}
public void setEmployees(Employee[] employees) {
this.employees = employees;
}
public NameListService() {
// 根據項目提供的Data類構建相應大小的employees數組
employees = new Employee[Data.EMPLOYEES.length];
for (int i = 0; i < employees.length; i++) {
//獲取通用數據
int type = Integer.parseInt(Data.EMPLOYEES[i][0]);
int id = Integer.parseInt(Data.EMPLOYEES[i][1]);
String name = Data.EMPLOYEES[i][2];
int age = Integer.parseInt(Data.EMPLOYEES[i][3]);
double salary = Double.parseDouble(Data.EMPLOYEES[i][4]);
Equipment equipment;
double bonus;
int stock;
// 再根據Data類中的數據,構建不同的對象,包括Employee、Programmer、Designer和Architect對象,以及相關聯的Equipment子類的對象
// 將對象存於數組中
switch (type) {
case Data.EMPLOYEE:
employees[i] = new Employee(id, name, age, salary);
break;
case Data.PROGRAMMER:
equipment = getCreatEquipment(i);
employees[i] = new Programmer(id, name, age, salary, equipment);
break;
case Data.DESIGNER:
equipment = getCreatEquipment(i);
bonus = Double.parseDouble(Data.EMPLOYEES[i][5]);
employees[i] = new Designer(id, name, age, salary, equipment, bonus);
break;
case Data.ARCHITECT:
equipment = getCreatEquipment(i);
bonus = Double.parseDouble(Data.EMPLOYEES[i][5]);
stock = Integer.parseInt(Data.EMPLOYEES[i][6]);
employees[i] = new Architect(id, name, age, salary, equipment, bonus, stock);
break;
default:
System.out.println("無職位");
}
}
}
private Equipment getCreatEquipment(int index) {
int type = Integer.parseInt(Data.EQUIPMENTS[index][0]);
switch (type) {
case Data.PC:
return new PC(Data.EQUIPMENTS[index][1], Data.EQUIPMENTS[index][2]);
case Data.NOTEBOOK:
return new NoteBook(Data.EQUIPMENTS[index][1], Double.parseDouble(Data.EQUIPMENTS[index][2]));
case Data.PRINTER:
return new Printer(Data.EQUIPMENTS[index][1], Data.EQUIPMENTS[index][2]);
default:
System.out.println("沒有此設備");
}
return null;
}
/**
* 返回所有員工
* @return 所有員工
*/
public Employee[] getAllEmployees() {
return employees;
}
/**
*
* @param id 員工的id
* @return 對應員工
* @throws TeamException 找不到指定員工
*/
public Employee getEmployee(int id) {
for (Employee employee : employees
) {
if (employee.getId() == id){
return employee;
}
}
throw new TeamException("Can Not Found ID="+id+"'s Employee!");
}
}
Status.java
package pers.jsc.dispatch.service;
/**
* @author 金聖聰
* @title: Status
* @projectName TeamDispatchApp
* @description: 成員狀態
* @date 2019/5/8 23:53
*/
public class Status {
private final String NAME;
private Status(String name) {
this.NAME = name;
}
public static final Status FREE = new Status("FREE");
public static final Status VOCATION = new Status("VOCATION");
public static final Status BUSY = new Status("BUSY");
public String getNAME() {
return NAME;
}
@Override
public String toString() {
return NAME;
}
}
TeamService.java
package pers.jsc.dispatch.service;
import pers.jsc.dispatch.domain.Employee;
import pers.jsc.dispatch.domain.domainexte.Architect;
import pers.jsc.dispatch.domain.domainexte.Designer;
import pers.jsc.dispatch.domain.domainexte.Programmer;
import pers.jsc.dispatch.exception.TeamException;
/**
* @author 金聖聰
* @title: TeamService
* @projectName TeamDispatchApp
* @description: 關於開發團隊成員的管理:添加、刪除等
* @date 2019/5/9 16:34
*/
public class TeamService {
/**
* 靜態變數,用來為開發團隊新增成員自動生成團隊中的唯一ID,即memberId。(提示:應使用增1的方式)
*/
private static int counter = 1;
/**
* 表示開發團隊最大成員數
*/
private final int MAX_MEMBER = 5;
/**
* 用來保存當前團隊中的各成員對象
*/
private Programmer[] team = new Programmer[MAX_MEMBER];
/**
* 記錄團隊成員的實際人數
*/
private int total = 0;
public static int getCounter() {
return counter;
}
public static void setCounter(int counter) {
TeamService.counter = counter;
}
public int getMAX_MEMBER() {
return MAX_MEMBER;
}
public void setTeam(Programmer[] team) {
this.team = team;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
/**
* 返回當前團隊的所有對象
* @return 包含所有成員對象的數組,數組大小與成員人數一致
*/
public Programmer[] getTeam() {
if (total != 0){
Programmer[] t = new Programmer[total];
for (int i = 0; i < t.length; i++) {
t[i] = team[i];
}
return t;
}
throw new TeamException("Nobody in Team");
}
/**
* 向團隊中添加成員
* @param e 待添加成員的對象
* @throws TeamException 添加失敗, TeamException中包含了失敗原因
*/
public void addMember(Employee e) throws TeamException {
// 成員已滿,無法添加
if (total >= MAX_MEMBER){
throw new TeamException("成員已滿,無法添加");
}
// 該成員不是開發人員,無法添加
if (!(e instanceof Programmer)){
throw new TeamException("該成員不是開發人員,無法添加");
}
Programmer p = (Programmer) e;
// 該員工已在本開發團隊中
if (isExit(p)){
throw new TeamException("該員工已在本開發團隊中");
}
// 該員工已是某團隊成員
// 該員正在休假,無法添加
String busy = "BUSY";
String vocation = "VOCATION";
if (busy.equals(p.getStatus().getNAME())){
throw new TeamException("該員工已是某團隊成員");
}else if (vocation.equals(p.getStatus().getNAME())){
throw new TeamException("該員正在休假,無法添加");
}
int numOfArch = 0;
int numOfDesr = 0;
int numOfPror = 0;
for (int i = 0; i < total; i++) {
if (team[i] instanceof Architect){
numOfArch++;
}else if (team[i] instanceof Designer){
numOfDesr++;
}else if (team[i] instanceof Programmer){
numOfPror++;
}
}
// 團隊中至多只能有一名架構師
// 團隊中至多只能有兩名設計師
// 團隊中至多只能有三名程式員
if (p instanceof Architect){
if (numOfArch >= 1){
throw new TeamException("團隊中至多只能有一名架構師");
}
}else if (p instanceof Designer){
if (numOfDesr >= 2){
throw new TeamException("團隊中至多只能有兩名設計師");
}
}else if (p instanceof Programmer){
if (numOfPror >= 3){
throw new TeamException("團隊中至多只能有三名程式員");
}
}
p.setStatus(Status.BUSY);
p.setMemberId(counter++);
team[total++] = p;
}
/**
* 從團隊中刪除成員
* @param memberId 待刪除成員的memberId
* @throws TeamException 找不到指定memberId的員工,刪除失敗
*/
public void removeMember(int memberId) throws TeamException {
int i = 0;
for (; i < total; i++) {
if (team[i].getMemberId() == memberId){
team[i].setStatus(Status.FREE);
break;
}
}
if ( i == total){
throw new TeamException("找不到該成員,刪除失敗!");
}
for (int j = i+1; j < total; j++) {
//往前覆蓋
team[j-1] = team[j];
}
team[--total] = null;
}
private boolean isExit(Programmer p){
for (int i = 0; i < total; i++) {
if (team[i].getId() == p.getId()){
return true;
}
}
return false;
}
}
Utils
TSUtility.java
package pers.jsc.dispatch.utils;
import java.util.*;
/**
* @author shkstart Email:[email protected]
* @Description 項目中提供了TSUtility.java類,可用來方便地實現鍵盤訪問。
* @date 2019年2月12日上午12:02:58
*/
public class TSUtility {
private static Scanner scanner = new Scanner(System.in);
/**
* @return 返回值為用戶鍵入1’-’4’中的字元。
* @Description 該方法讀取鍵盤,如果用戶鍵入’1’-’4’中的任意字元,則方法返回。
* @author shkstart
* @date 2019年2月12日上午12:03:30
*/
public static char readMenuSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4') {
System.out.print("選擇錯誤,請重新輸入:");
} else {
break;
}
}
return c;
}
/**
* 該方法提示並等待,直到用戶按回車鍵後返回。
*/
public static void readReturn() {
System.out.print("按回車鍵繼續...");
readKeyBoard(100, true);
}
/**
* @return 返回鍵盤讀取不超過2位的整數
* @Description 該方法讀一個長度不超過2位的整數。
* @author shkstart
* @date 2019年2月12日上午12:04:04
*/
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("數字輸入錯誤,請重新輸入:");
}
}
return n;
}
/**
* @return 返回鍵盤讀取‘Y’或’N’
* @Description 從鍵盤讀取‘Y’或’N’,並將其作為方法的返回值。
* @author shkstart
* @date 2019年2月12日上午12:04:45
*/
public static char readConfirmSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false).toUpperCase();
c = str.charAt(0);
if (c == 'Y' || c == 'N') {
break;
} else {
System.out.print("選擇錯誤,請重新輸入:");
}
}
return c;
}
private static String readKeyBoard(int limit, boolean blankReturn) {
String line = "";
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if (line.length() == 0) {
if (blankReturn) {
return line;
} else {
continue;
}
}
if (line.length() < 1 || line.length() > limit) {
System.out.print("輸入長度(不大於" + limit + ")錯誤,請重新輸入:");
continue;
}
break;
}
return line;
}
}
View
TeamView.java
package pers.jsc.dispatch.view;
import pers.jsc.dispatch.domain.Employee;
import pers.jsc.dispatch.domain.domainexte.Programmer;
import pers.jsc.dispatch.exception.TeamException;
import pers.jsc.dispatch.service.NameListService;
import pers.jsc.dispatch.service.TeamService;
import pers.jsc.dispatch.utils.TSUtility;
/**
* @author 金聖聰
* @title: TeamView
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 18:21
*/
public class TeamView {
/**
* 供類中的方法使用
*/
private NameListService listSvc = new NameListService();
private TeamService teamSvc = new TeamService();
/**
* 主界面顯示及控制方法
*/
public void enterMainMenu() {
boolean flag = true;
char key = '0';
do {
char loop = '1';
if (key != loop) {
listAllEmployees();
}
System.out.print("1-團隊列表 2-添加團隊成員 3-刪除團隊成員 4-退出 請選擇(1-4):");
key = TSUtility.readMenuSelection();
switch (key) {
case '1':
getTeam();
break;
case '2':
addMember();
break;
case '3':
deleteMember();
break;
case '4':
System.out.print("確認是否退出(Y/N):");
char notExit = 'N';
flag = TSUtility.readConfirmSelection() == notExit;
break;
default:
System.out.println("輸入錯誤");
}
} while (flag);
}
/**
* 以表格形式列出公司所有成員
*/
private void listAllEmployees() {
System.out.println("-------------------------------開發團隊調度軟體--------------------------------\n");
System.out.println("ID\t姓名\t\t年齡\t\t工資\t\t職位\t\t狀態\t\t獎金\t\t股票\t\t領用設備");
NameListService nameListService = new NameListService();
printNameList(nameListService.getAllEmployees());
System.out.println("-----------------------------------------------------------------------------");
}
private void printNameList(Employee[] employees) {
for (Employee e : employees
) {
System.out.println(e);
}
}
/**
* 顯示團隊成員列表操作
*/
private void getTeam() {
System.out.println("\n--------------------團隊成員列表---------------------");
System.out.println("TID/ID\t姓名\t\t年齡\t\t工資\t\t職位\t\t獎金\t\t股票");
try {
Programmer[] team = teamSvc.getTeam();
for (Programmer p : team) {
System.out.println(" " + p.getDetails4Team());
}
} catch (TeamException t) {
System.out.println(t.getMessage());
} finally {
System.out.println("-----------------------------------------------------");
}
}
/**
* 實現添加成員操作
*/
private void addMember() {
System.out.println("\n---------------------添加成員---------------------");
System.out.println("請輸入要添加的員工ID:");
int id = TSUtility.readInt();
try {
teamSvc.addMember(listSvc.getEmployee(id));
System.out.println("添加成功");
} catch (TeamException t) {
System.out.println("添加失敗,原因:" + t.getMessage());
} finally {
TSUtility.readReturn();
}
}
/**
* 實現刪除成員操作
*/
private void deleteMember() {
System.out.println("---------------------刪除成員---------------------");
System.out.println("請輸入要刪除員工的TID:");
int tid = TSUtility.readInt();
System.out.println("確認是否刪除(Y/N):");
char delete = TSUtility.readConfirmSelection();
switch (delete) {
case 'Y':
try {
teamSvc.removeMember(tid);
System.out.println("刪除成功!");
break;
} catch (TeamException t) {
System.out.println(t.getMessage());
} finally {
TSUtility.readReturn();
}
case 'N':
break;
default:
TSUtility.readReturn();
}
}
public static void main(String[] args) {
new TeamView().enterMainMenu();
}
}
Test類
NameListServiceTest.java
package pers.jsc.dispatch.service;
import pers.jsc.dispatch.domain.Employee;
import org.junit.Test;
/**
* @author 金聖聰
* @title: NameListServiceTest
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 3:03
*/
public class NameListServiceTest {
@Test
public void testNameListService() {
NameListService service = new NameListService();
for (Employee employee : service.getEmployees()
) {
System.out.println(employee);
}
}
@Test
public void testGetAllEmployees() {
NameListService service = new NameListService();
for (Employee employee : service.getAllEmployees()
) {
System.out.println(employee);
}
}
@Test
public void testGetEmployee() {
NameListService service = new NameListService();
try {
System.out.println(service.getEmployee(12));
}catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
TeamServiceTest.java
package pers.jsc.dispatch.service;
import org.junit.Test;
import pers.jsc.dispatch.domain.Employee;
import pers.jsc.dispatch.domain.domainexte.Programmer;
/**
* @author 金聖聰
* @title: TeamServiceTest
* @projectName TeamDispatchApp
* @description: TODO
* @date 2019/5/9 16:45
*/
public class TeamServiceTest {
@Test
public void getTeam() {
TeamService teamService = new TeamService();
teamService.setTotal(5);
Programmer[] programmers = teamService.getTeam();
for (Programmer p: programmers
) {
System.out.println(p);
}
}
@Test
public void addMember() {
TeamService teamService = new TeamService();
teamService.addMember(new NameListService().getEmployee(12));
Programmer[] programmers = teamService.getTeam();
for (Programmer p: programmers
) {
System.out.println(p);
}
}
@Test
public void removeMember() {
TeamService teamService = new TeamService();
teamService.addMember(new NameListService().getEmployee(12));
teamService.addMember(new NameListService().getEmployee(11));
teamService.removeMember(2);
Programmer[] programmers = teamService.getTeam();
for (Programmer p: programmers
) {
System.out.println(p);
System.out.println(p.getMemberId());
}
}
}