開發人員調度軟體

来源:https://www.cnblogs.com/jsccc520/archive/2019/05/09/10841088.html
-Advertisement-
Play Games

開發人員調度軟體 這幾天在學校弄畢設,異常那邊找了個簡單數組l類項目做了一下 只為記錄,好記性不如爛筆頭 有誤請指正 ありがとうございます。 我的公眾號 作者:晨鐘暮鼓c個人微信公眾號:程式猿的月光寶盒 1.首先,項目名字是開發人員調動軟體,基於控制台,需求如下 2.涉及知識點 1. 類的繼承性和多 ...


開發人員調度軟體

這幾天在學校弄畢設,異常那邊找了個簡單數組l類項目做了一下

只為記錄,好記性不如爛筆頭

有誤請指正

ありがとうございます。

我的公眾號

作者:晨鐘暮鼓c
個人微信公眾號:程式猿的月光寶盒

1.首先,項目名字是開發人員調動軟體,基於控制台,需求如下

圖片

圖片

圖片

圖片

圖片

圖片

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

項目結構:

圖片

圖片

圖片

圖片


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 基於flask的網頁聊天室(一) 基本目標 基於flask實現的web聊天室,具有基本的登錄註冊,多人發送消息,接受消息 擴展目標 除基本目標外添加當前線上人數,消息回覆,markdown支持,歷史消息等 創建項目 首先創建基本的文件結構: auth和chat通過藍圖建立: 例如auth: from ...
  • 今天老師又沒有講新課,不過講了練習題,擴展了一下我們的思維。 今天就講一下如何獲取時間吧。 代碼: //一般在程式開頭寫一個,結尾寫一個,用結尾的減開頭, //就能算出這個程式運行的時間 今天就這些啦!!! 下周講JDBC,有點期待,喝喝喝!!! 字數不夠,發不了首頁,雖然每天都被首頁踢出來。喝喝喝 ...
  • Mac OS下修改Python的鏡像源 步驟: 切換到家目錄 創建目錄 .pip 並切換到該目錄 創建 pip.conf 文件並寫入配置信息 以上採用的是 清華大學 的鏡像源,經過測試比較穩定 也可以用其他: 清華:https://pypi.tuna.tsinghua.edu.cn/simple 阿 ...
  • apache配置文件httpd.conf修改“AddType application/x-httpd-php .xxx”,“.xxx”是想要的尾碼名。 把文件尾碼改成自定義的尾碼名。 phpStorm為防止報錯,在Settings->File Types->Recognized File Types ...
  • Kafka集群搭建分為單節點的偽分散式集群和多節點的分散式集群兩種,首先來看一下單節點偽分散式集群安裝。單節點偽分散式集群是指集群由一臺ZooKeeper伺服器和一臺Kafka broker伺服器組成,如下圖所示: 為了搭建單節點Kafka集群,需要依次安裝如下軟體:安裝Java-->安裝ZooKe ...
  • 什麼是ABA? ABA的危害? ABA的解決方法? AtomicStampedReference是什麼? AtomicStampedReference是怎麼解決ABA的? ...
  • 10.1 數據結構特點 10.1.1 Scala集合基本介紹 uml => 統一建模語言 1) Scala同時支持不可變集合和可變集合,不可變集合可以安全的併發訪問 兩個主要的包 不可變集合:scala.collection.immutable 可變集合:scala.collection.mutab ...
  • 這裡整理一份 Java 的學習路線,希望對想要學習 Java 還沒有頭緒的小伙伴有所幫助~ ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...