开发人员调度软件

开发人员调度软件

这几天在学校弄毕设,异常那边找了个简单数组l类项目做了一下

只为记录,好记性不如烂笔头

有误请指正

ありがとうございます。

我的公众号

作者: 晨钟暮鼓c
个人微信公众号: 程序猿的月光宝盒
开发人员调度软件_第1张图片

1.首先,项目名字是开发人员调动软件,基于控制台,需求如下

开发人员调度软件_第2张图片

开发人员调度软件_第3张图片

开发人员调度软件_第4张图片

开发人员调度软件_第5张图片

开发人员调度软件_第6张图片

开发人员调度软件_第7张图片

2.涉及知识点

  1. 类的继承性和多态性
  2. 对象的值传递、接口
  3. static和final修饰符
  4. 特殊类的使用:包装类、抽象类、内部类
  5. 异常处理

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());
        }
    }
}

项目结构:

开发人员调度软件_第8张图片

开发人员调度软件_第9张图片

开发人员调度软件_第10张图片

开发人员调度软件_第11张图片

你可能感兴趣的:(开发人员调度软件)