项目开发团队分配管理软件

学习大纲

熟悉Java面向对象的高级特性,进一步掌握编程技巧和调试技巧
主要掌握技术:
类的继承性和多态性
对象的值传递、接口
static和final修饰符
特殊类的使用:包装类、抽象类、内部类
异常处理
Java基本语法和流程控制
数组,ArrayList集合

需求说明

该软件实现以下功能:
软件启动时,首先进入登录界面进行注册和登录功能。
当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。
然后可以对开发人员进行增删改操作
人员添加成功后,根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目。
组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。
团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。

系统功能结构

在这里插入图片描述

系统流程:
在这里插入图片描述

模块说明

com.team.view 模块为主控模块,负责菜单的显示和处理用户操作
com.team.service 模块为实体对象(Employee及其子类如程序员等)的管理模块, NameListService和TeamService类分别用各自的数组来管理公司员工和开发团队成员对象
ProjectService是对项目的操作对象类
domain模块为Employee及其子类等JavaBean类所在的包

在这里插入图片描述

实体类

接口的作用:对于实现的方法,描述其相关的设备功能
Architect:构造师;Designer:设计师;Programmer:程序员;Employee:员工;NotBook:笔记本电脑;PC:台式电脑;Printer:打印机;Probject:项目
在这里插入图片描述

IndexView测试类。也是程序的入口

项目开发团队分配管理登录,这里都要注册用户,用到了注册模块(IndexView)
在这里插入图片描述
实现注册方法
如果没有账户则需要注册
如果有账号则直接进行登录
实现登录功能
判断用户输入的值是否正确
如果正确则进入软件菜单
如果错误则重新输入,限制次数只有5次,超过次数则程序停止,重新启动
实现修改用户密码功能
可以实现对用户名,密码,或者两者都可以进行修改即可

package com.team.view;

import java.util.Random;
import java.util.Scanner;

/**
 * @author :卿艾迪
 * @date :Created in 2021/3/25 11:06
 * @description:项目的登录和注册
 */
public class LoginView {
    //首先给定属性:登录用户和密码
    private String userName = "";
    private String password = "";

    //注册功能
    public void regist() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        System.out.println("开始注册:");
        System.out.println("请输入你的注册账户名称:");
        String userName = TSUtility.readKeyBoard(4, false);
        this.userName = userName;
        System.out.println("请输入你的注册密码:");
        String password = TSUtility.readKeyBoard(8, false);
        this.password = password;
        System.out.println("注册成功!请登录!");

    }

    //登录功能
    public void login() throws InterruptedException {
        //登录失败的次数限制
        int count = 5;
        boolean flag = true;
        while (flag) {
            System.out.println("🐱********************🐱");
            System.out.println("🐱***   <登录界面>   ***🐱");
            System.out.println("🐱***    (::)     ***🐱");
            System.out.println("🐱********************🐱");

            System.out.println("请输入你的登录账户名称:");
            String userName = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入你的登录密码:");
            String password = TSUtility.readKeyBoard(8, false);
            //未注册
            if (this.userName.length() == 0 || this.password.length() == 0) {
                System.out.println("未检测到您的账号,请您先注册!");
                regist();

            }
            //已注册
            //正常登录
            else if (this.userName.equals(userName) && this.password.equals(password)) {
                TSUtility.loadSpecialEffects();
                System.out.println("登陆成功!欢迎您:" + userName);
                flag = false;
            } else {
                if (count <= 0) {
                    System.out.println("登录次数不足!退出!");
                    return;
                } else {
                    count--;
                    System.out.println("登录失败!用户名或密码不匹配!");
                    System.out.println("登录次数还剩" + count + "次,请重新输入:");

                }
            }
        }

    }

    //修改功能
    public void update() throws InterruptedException {
        boolean flag = true;
        while (flag) {
            System.out.println("********************🐱");
            System.out.println("***   <修改界面>   ***");
            System.out.println("***     (:      ***🐱");
            System.out.println("********************🐱");

            System.out.println("请输入你需要修改的类型:");
            System.out.println("1(修改用户名)");
            System.out.println("2(修改密码名)");
            System.out.println("3(修改用户名和密码名)");
            System.out.println("4(不修改,退出)");
            Scanner sc = new Scanner(System.in);
            String options = sc.next();
            if (options.equals("1")) {
                System.out.println("请输入你的修改的账户名称:");
                String userName = TSUtility.readKeyBoard(4, false);
                this.userName = userName;
                System.out.println("修改成功!");
            } else if (options.equals("2")) {
                System.out.println("请输入你的修改密码:");
                String pass= TSUtility.readKeyBoard(8, false);
                this.pass = pass;
                System.out.println("修改成功!");
            } else if (options.equals("3")) {
                System.out.println("请输入你的修改的账户名称:");
                String userName = TSUtility.readKeyBoard(4, false);
                this.userName = userName;
                System.out.println("请输入你的修改密码:");
                String password = TSUtility.readKeyBoard(8, false);
                this.pass = pass;
                System.out.println("修改成功!");
            }
            else if (options.equals("4")) {
                System.out.println("退出中");
                TSUtility.loadSpecialEffects();
                flag = false;
            }
            else  {
                System.out.println("输入错误!请输入“1”或者“2”或者“3”或者“4”:");
            }
        }
    }


}

软件主菜单:主要进行的功能操作
在这里插入图片描述

开发人员管理菜单
在这里插入图片描述
这里包括业务层的:

NameListService团队队员的业务操作:

如果添加操作因某种原因失败,将显示类似以下信息(失败原因视具体原因而不同):
1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4):2

---------------------添加成员---------------------
请输入要添加的员工ID:2
添加失败,原因:该员工已是某团队成员
按回车键继续…
失败信息包含以下几种: (需要抛出自定义异常)
成员已满,无法添加
该成员不是开发人员,无法添加
该员工已在本开发团队中
该员工已是某团队成员
团队中至多只能有一名架构师(以下判断可借用instanceof进行判断)
团队中至多只能有两名设计师
团队中至多只能有三名程序员

先初始化里面的数据;
getAllEmployees():得到所有员工数据集合;
getEmployee():得到当前员工;
addEmployee():员工的增加;
delEmployee():员工的删除;
showEmployee():员工的查看;
modifyEmployee():员工的修改 (目前只修改姓名,年龄,工资即可)。

package com.team.service;

import com.team.domain.*;
import com.team.view.TSUtility;

import java.util.ArrayList;

public class NameListService {
    //用来装员工的数据集合
    private ArrayList<Employee> employees = new ArrayList<>();

    //添加员工的id
    private int count = 1;

    //初始化默认值
    {
        employees.add(new Employee(count, "马云 ", 22, 3000));
        employees.add(new Architect(++count, "马化腾", 32, 18000, new NoteBook("联想T4", 6000), 60000, 5000));
        employees.add(new Programmer(++count, "李彦宏", 23, 7000, new PC("戴尔", "NEC 17寸")));
        employees.add(new Programmer(++count, "刘强东", 24, 7300, new PC("戴尔", "三星 17寸")));
        employees.add(new Designer(++count, "雷军 ", 50, 10000, new Printer("激光", "佳能2900"), 5000));
        employees.add(new Programmer(++count, "任志强", 30, 16800, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "柳传志", 45, 35500, new PC("华硕", "三星 17寸"), 8000));
        employees.add(new Architect(++count, "杨元庆", 35, 6500, new Printer("针式", "爱普生20k"), 15500, 1200));
        employees.add(new Designer(++count, "史玉柱", 27, 7800, new NoteBook("惠普m6", 5800), 1500));
        employees.add(new Programmer(++count, "丁磊 ", 26, 6600, new PC("戴尔", "NEC17寸")));
        employees.add(new Programmer(++count, "张朝阳 ", 35, 7100, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "杨致远", 38, 9600, new NoteBook("惠普m6", 5800), 3000));
    }

    //得到所有员工数据集合
    public ArrayList<Employee> getAllEmployees() {

        return employees;
    }

    //得到当前员工
    public Employee getEmployee(int id) throws TeamException {

        for (Employee employee : employees) {

            if (employee.getId() == id) {
                return employee;
            }
        }
        throw new TeamException("该员工不存在");
    }

    //员工的增加
    public void addEmployee() throws InterruptedException {
        System.out.println("请输入需要添加的雇员的职位:");
        System.out.println("1(无职位)");
        System.out.println("2(程序员)");
        System.out.println("3(设计师)");
        System.out.println("4(架构师)");
        String c = String.valueOf(TSUtility.readMenuSelection());
        switch (c) {
            case "1": {
                //无职位 new Employee(count++,"马云 ",22,3000)
                System.out.println("`当前雇员职位分配为:无`");
                System.out.println("请输入当前雇员的姓名:");
                String name = TSUtility.readKeyBoard(4, false);
                System.out.println("请输入当前雇员的年龄:");
                int age = TSUtility.readInt();
                System.out.println("请输入当前雇员的工资:");
                Double salary = TSUtility.readDouble();
                Employee employee = new Employee(++count, name, age, salary);
                employees.add(employee);
                System.out.println("人员添加成功!");
                TSUtility.readReturn();
                break;
            }
            case "2": {
                //程序员 new Programmer(count++,"张朝阳 ",35,7100,new PC("华硕","三星 17寸"))
                System.out.println("`当前雇员职位分配为:程序员`");
                System.out.println("请输入当前雇员的姓名:");
                String name = TSUtility.readKeyBoard(4, false);
                System.out.println("请输入当前雇员的年龄:");
                int age = TSUtility.readInt();
                System.out.println("请输入当前雇员的工资:");
                Double salary = TSUtility.readDouble();
                System.out.println("请为当前程序员配一台好的台式电脑:");
                PC pc = new PC().addPC();
                Programmer programmer = new Programmer(++count, name, age, salary, pc);
                employees.add(programmer);
                System.out.println("人员添加成功!");
                TSUtility.readReturn();
                break;
            }
            case "3": {
                //设计师 new Designer(count++,"史玉柱",27,7800,new NoteBook("惠普m6",5800),1500)
                System.out.println("`当前雇员职位分配为:设计师`");
                System.out.println("请输入当前雇员的姓名:");
                String name = TSUtility.readKeyBoard(4, false);
                System.out.println("请输入当前雇员的年龄:");
                int age = TSUtility.readInt();
                System.out.println("请输入当前雇员的工资:");
                Double salary = TSUtility.readDouble();
                System.out.println("请为当前设计师配一台好的笔记本电脑:");
                NoteBook noteBook = new NoteBook().addNoteBook();
                System.out.println("请输入当前设计师的奖金:");
                Double bonus = TSUtility.readDouble();
                Designer designer = new Designer(++count, name, age, salary, noteBook, bonus);
                employees.add(designer);
                System.out.println("人员添加成功!");
                TSUtility.readReturn();

                break;
            }
            default: {
                //架构师 new Architect(count++,"杨元庆",35,6500,new Printer("针式","爱普生20k"),15500,1200)
                System.out.println("`当前雇员职位分配为:架构师`");
                System.out.println("请输入当前雇员的姓名:");
                String name = TSUtility.readKeyBoard(4, false);
                System.out.println("请输入当前雇员的年龄:");
                int age = TSUtility.readInt();
                System.out.println("请输入当前雇员的工资:");
                Double salary = TSUtility.readDouble();
                System.out.println("请为当前架构师配一台好的打印设备:");
                Printer printer = new Printer().addPrinter();
                System.out.println("请输入当前架构师的奖金:");
                Double bonus = TSUtility.readDouble();
                System.out.println("请输入当前架构师的股票:");
                int stock = TSUtility.readstock();
                Architect architect = new Architect(++count, name, age, salary, printer, bonus, stock);
                employees.add(architect);
                System.out.println("人员添加成功!");
                TSUtility.readReturn();
                break;
            }
        }
    }

    //员工的删除
    public void delEmployee(int id)  {

        boolean flag = false;
        for (int i = 0; i < employees.size(); i++) {
            if (employees.get(i).getId() == id) {
                employees.remove(i);
                for (i = id; i <= employees.size(); i++) {
                    employees.get(i - 1).setId(employees.get(i - 1).getId() - 1);
                }
                flag = true;
            }
        }
        if (flag) {
            System.out.println("删除成功!");
            count--;
        } else {
            try {
                throw new TeamException("该员工不存在");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }

    }

    //员工的查看
    public void showEmployee() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
        for (Employee employee : employees) {
            System.out.println(" " + employee);
        }
    }

    //员工的修改 (目前只修改姓名,年龄,工资即可)
    public void modifyEmployee(int id) throws  InterruptedException {
        boolean flag = false;
        for (int i = 0; i < employees.size(); i++) {
            Employee emp = employees.get(i);

            if (employees.get(i).getId() == id) {
                System.out.print("姓名(" + emp.getName() + "):");
                String name = TSUtility.readString(4, emp.getName());
                System.out.print("年龄(" + emp.getAge() + "):");
                int age = Integer.parseInt(TSUtility.readString(2,emp.getAge()+""));
                System.out.print("工资(" + emp.getSalary() + "):");
                double salary =Double.parseDouble(TSUtility.readString(10, emp.getSalary()+""));
                emp.setName(name);
                emp.setAge(age);
                emp.setSalary(salary);
                employees.set(i,emp);
                flag = true;
            }
        }
        if (flag) {
            System.out.println("修改成功!");
        } else {
            try {
                throw new TeamException("该员工不存在");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }
    }

}

团队的添加以及团队成员的添加:

TeamView团队以及队员的添加

listSvc: NameListService = new NameListService()
teamSvc: TeamService = new TeamService()

  • listSvc和teamSvc属性:供类中的方法使用
    enterMainMenu ()方法:主界面显示及控制方法。
    以下方法仅供enterMainMenu()方法调用:
    listAllEmployees ()方法:以表格形式列出公司所有成员
    getTeam()方法:显示团队成员列表操作
    addMember ()方法:实现添加成员操作
    deleteMember ()方法:实现删除成员操作

enterMainMenu(): void
listAllEmployees(): void
getTeam():void
addMember(): void
deleteMember(): void
main(args: String[]) : void

package com.team.view;

import com.team.domain.Employee;
import com.team.domain.Programmer;
import com.team.service.NameListService;
import com.team.service.TeamException;
import com.team.service.TeamService;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author BaBa
 * @Version 1/0
 */
/*
listSvc: NameListService = new NameListService()
teamSvc: TeamService = new TeamService()
* listSvc和teamSvc属性:供类中的方法使用
enterMainMenu ()方法:主界面显示及控制方法。

以下方法仅供enterMainMenu()方法调用:
listAllEmployees ()方法:以表格形式列出公司所有成员
getTeam()方法:显示团队成员列表操作
addMember ()方法:实现添加成员操作
deleteMember ()方法:实现删除成员操作
*
enterMainMenu(): void
listAllEmployees(): void
getTeam():void
addMember(): void
deleteMember(): void
main(args: String[]) : void
其他(可根据自己需要加其他方法
*/
public class TeamView {
    NameListService listSvc = new NameListService();
    TeamService teamSvc = new TeamService();
    private ArrayList<Programmer[]> team = new ArrayList<>();


    //通过该方法,创建团队新数组,每添加一次,把团队队员放在一个数组中,通过index调用项目为每一个项目添加开发团队名称
    public ArrayList<Programmer[]> getManyTeam(NameListService b) throws InterruptedException {
        listSvc = b;
        boolean flag = true;
        char key = 0;

        do {
            System.out.println("##########################");
            System.out.println("#####                #####");
            System.out.println("#####   团队调度界面   #####");
            System.out.println("#####                #####");
            System.out.println("##########################");
            System.out.print("1-添加团队 2-查看团队 3-删除团队 4-退出   请选择(1-4):");
            key = TSUtility.readMenuSelection();
            System.out.println();
            switch (key) {
                case '1':
                    enterMainMenu();
                    break;
                case '2':
                    System.out.println("================================团队列表================================");
                    try {
                        if (team.size() == 0) {
                            throw new InterruptedException();
                        } else {
                            System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
                            for (Programmer[] team : team) {
                                for (int i = 0; i < team.length; i++) {
                                    System.out.println(team[i]);
                                }
                                System.out.println("======================================================================");
                            }
                        }
                    } catch (InterruptedException i) {
                        System.out.println("当前没有任何团队,请重新添加团队!" + i.getMessage());
                    }
                    break;
                case '3':
                    System.out.println("请输入想要删除第几个团队");
                    int num = TSUtility.readInt();
                    try {
                        if (num > team.size()) {
                            throw new InterruptedException();
                        } else {
                            System.out.print("确认是否删除(Y/N):");
                            char de = TSUtility.readConfirmSelection();
                            if (de == 'Y') {
                                team.remove(num - 1);
                            } else {
                                System.out.println("请考虑清楚!");
                            }
                        }
                    } catch (InterruptedException interruptedException) {
                        System.out.println("没有该团队,请正常输入!" + "目前团队只有" + team.size() + "个" + interruptedException.getMessage());
                    }
                    break;
                case '4':
                    System.out.print("确认是否退出(Y/N):");
                    char yn = TSUtility.readConfirmSelection();
                    if (yn == 'Y') {
                        flag = false;
                        System.out.println("退出中");
                        TSUtility.loadSpecialEffects();
                    }
                    break;
                default:
                    break;
            }
        } while (flag);
        return team;
    }

    //团队成员调度界面(增加,删除,查看团队成员)
    public void enterMainMenu() throws InterruptedException {
        boolean loopFlag = true;
        char key = 0;
        do {
            if (key != '1') {
                listAllEmployees();
            }
            System.out.print("1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):");
            key = TSUtility.readMenuSelection();
            System.out.println();
            switch (key) {
                case '1':
                    listTeam();
                    System.out.println();
                    break;
                case '2':
                    addMember();
                    System.out.println();
                    break;
                case '3':
                    deleteMember();
                    System.out.println();
                    break;
                case '4':
                    System.out.print("确认是否退出(Y/N):");
                    char yn = TSUtility.readConfirmSelection();
                    if (yn == 'Y') {
                        if (teamSvc.getTeam().length == 0) {
                            loopFlag = false;
                        } else {
                            team.add(teamSvc.getTeam());
                            //执行这一步是为了在进入到该界面时,把之前的数据全部删除
                            teamSvc.clearTeam();
                            loopFlag = false;
                        }
                        System.out.println("退出中");
                        TSUtility.loadSpecialEffects();
                    }
                    break;
                default:
                    break;
            }
        } while (loopFlag);
        //    public void enterMainMenu() throws InterruptedException {
//        boolean b = true;
//        while (b) {
//            System.out.println("1-团队列表  2-添加团队队员  3-删除团队队员  4-退出  请选择(1-4):");
//            char choice = TSUtility.readMenuSelection();
//            switch (choice) {
//                case '1':
//                    listTeam();
//                    break;
//                case '2':
//                    listAllEmployees();
//                    addMember();
//                    break;
//                case '3':
//                    listTeam();
//                    deleteMember();
//                    break;
//                case '4':
//                    System.out.print("确认是否退出(Y/N):");
//                    char c1 = TSUtility.readConfirmSelection();
//                    if (c1 == 'Y') {
//                        //在集合中添加一个团队
//                        team.add(teamSvc.getTeam());
//                        //初始化团队
//                        b = false;
//                    }
//                    break;
//            }
//        }
//    }
    }

    //显示团队成员列表
    public ArrayList<Programmer[]> getTeam() {
        return team;
    }

    //开发人员调度界面
    public void listAllEmployees() {
        /* NameListService listSvc = new NameListService();
           TeamService teamSvc = new TeamService();
        * */
        System.out.println("-----------------------开发团队调度界面-----------------------");
        ArrayList<Employee> allEmployees = listSvc.getAllEmployees();
        try {
            if (allEmployees.size() == 0) {
                throw new Exception();
            } else {
                System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
                for (int i = 0; i < allEmployees.size(); i++) {
                    System.out.println(" " + allEmployees.get(i));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("-----------------------------------------------------------");
    }

    //显示成员列表
    public void listTeam() {
        /* NameListService listSvc = new NameListService();
           TeamService teamSvc = new TeamService();
        * */
        System.out.println("-------------------------团队成员列表------------------------");
        Programmer[] team = teamSvc.getTeam();
        try {
            if (team.length == 0) {
                throw new Exception();
            } else {
                System.out.println("TID/ID\t姓名\t\t年龄\t\t 工资\t 职位\t 奖金\t 股票");
                for (int i = 0; i < team.length; i++) {
                    System.out.println(" " + team[i].getDetailsForTeam());
                }
                System.out.println("---------------------------------------------------------");
            }

        } catch (Exception e) {
            System.out.println("开发团队目前没有成员!");
            System.out.println("---------------------------------------------------------");
        }
    }

    //增加团队成员
    public void addMember() {
        /* NameListService listSvc = new NameListService();
           TeamService teamSvc = new TeamService();
        * */
        System.out.println("-----------------添加成员------------------");
        System.out.print("请输入要添加的员工ID:");
        int id = TSUtility.readInt();

        try {
            Employee e = listSvc.getEmployee(id);
            teamSvc.addMember(e);
            System.out.println("添加成功");
        } catch (TeamException e) {
            System.out.println("添加失败,原因:" + e.getMessage());
        }
        TSUtility.readReturn();
        /*System.out.println("---------------------------添加团队队员--------------------------");
        System.out.println("请输入需要添加团队的TID");
        int id = TSUtility.readInt();
        int index = -1;
        //判断id是否匹配,匹配的话
        for (int i = 0; i < listSvc.getAllEmployees().size(); i++) {
            if (listSvc.getAllEmployees().get(i).getId() == id) {
                index = id;
                break;
            }
        }
        if (index == -1) {
            System.out.println("此id的开发团队成员不存在");
        } else {
            index--;
            try {
                Employee e = listSvc.getAllEmployees().get(index);
                teamSvc.addMember(e);
                System.out.println("添加成功");
            } catch (TeamException e) {
                System.out.println("添加失败" + e.getMessage());
            }
        }
        TSUtility.readReturn();
        System.out.println("---------------------------------------------------------");
        */


    }

    //删除团队成员
    public void deleteMember() {
        /* NameListService listSvc = new NameListService();
           TeamService teamSvc = new TeamService();
        * */
        System.out.println("---------------------删除成员---------------------");
        System.out.print("请输入要删除员工的TID:");
        int id = TSUtility.readInt();
        System.out.print("确认是否删除(Y/N):");
        char yn = TSUtility.readConfirmSelection();
        if (yn == 'N')
            return;

        try {
            teamSvc.removeMember(id);
            System.out.println("删除成功");
        } catch (TeamException e) {
            System.out.println("删除失败,原因:" + e.getMessage());
        }
        TSUtility.readReturn();
        /*if (teamSvc.getTeam().length == 0) {
            System.out.println("请重新输入增加团队成员以便于组成团队!");
        } else {
            System.out.println("---------------------------删除团队队员--------------------------");
            System.out.println("请输入需要删除团员的TID");
            //同上增添员工,只是后边不需要设置index的减
            int TId = TSUtility.readstock();
            int index = -1;
            for (int i = 0; i < teamSvc.getTeam().length; i++) {
                if (teamSvc.getTeam()[i].getMemberId() == TId) {
                    index = TId;
                    break;
                }
            }
            if (index == -1) {
                System.out.println("此id的开发团队成员不存在");
            } else {
                System.out.println("请您确认是否要删除:(Y/N)");
                char ch = TSUtility.readConfirmSelection();
                if (ch == 'Y') {
                    try {
                        teamSvc.removeMember(index);
                        System.out.println("删除成功");
                        System.out.println("---------------------------------------------------------");
                        System.out.println();
                    } catch (TeamException e) {
                        System.out.println("删除失败" + e.getMessage());
                    }
                } else System.out.println("取消操作删除该TID");
            }
        }
        TSUtility.readReturn();*/

    }

    //    public Programmer[] showTeam() {
//        System.out.println("-------------------------团队成员列表------------------------");
//        System.out.println("ID\t姓名\t\t年龄\t\t 工资\t 职位\t 奖金\t 股票");
//
//        Programmer[] team = teamSvc.getTeam();
//        try {
//            if (team.length == 0) {
//                throw new Exception();
//            }
//        } catch (Exception e) {
//            System.out.println("开发团队目前没有成员!");
//            System.out.println("---------------------------------------------------------");
//        }
//        return team;
//
//    }
}


TeamService:团队的业务操作

功能:关于开发团队成员的管理:添加、删除等
getTeam():返回team中所有程序员构成的数组
clearTeam():初始化当前团队成员数组
addMember(e: Employee)方法:向团队中添加成员
isExist(Programmer p)判断成员是否在所创建的团队中
removeMember(int memberId):删除指定memberId的程序员

package com.team.service;

import com.team.domain.Architect;
import com.team.domain.Designer;
import com.team.domain.Employee;
import com.team.domain.Programmer;

/*
* 功能:关于开发团队成员的管理:添加、删除等(还需要自行实现)。
说明:
counter为静态变量,用来为开发团队新增成员自动生成团队中的唯一ID,即memberId。(提示:应使用增1的方式)
MAX_MEMBER:表示开发团队最大成员数
team数组:用来保存当前团队中的各成员对象 (也可以用一个新的集合)
total:记录团队成员的实际人数

getTeam(): Programmer[]
addMember(e: Employee) throws TeamException: void
removeMember(memberId: int) throws TeamException: void
counter: int = 1
MAX_MEMBER: final int = 5
team: Programmer[] = new Programmer[MAX_MEMBER];
total: int = 0;
getTeam()方法:返回当前团队的所有对象
返回:包含所有成员对象的数组,数组大小与成员人数一致
addMember(e: Employee)方法:向团队中添加成员
参数:待添加成员的对象
异常:添加失败, TeamException中包含了失败原因
removeMember(memberId: int)方法:从团队中删除成员
参数:待删除成员的memberId
异常:找不到指定memberId的员工,删除失败
另外,可根据需要自行添加其他方法或重载构造器


*/
public class TeamService {
    //用于自动生成团队成员的memberId
    private static int counter = 1;
    //团队人数上限
    private final int MAX_MEMBER = 5;
    //保存当前团队成员
    private Programmer[] team = new Programmer[MAX_MEMBER];
    //团队实际人数
    private int total = 0;

    //无参构造器
    public TeamService() {
    }

    //返回team中所有程序员构成的数组
    public Programmer[] getTeam() {
        Programmer[] team = new Programmer[total];

        for (int i = 0; i < total; i++) {
            team[i] = this.team[i];
        }
        return team;
    }

    //初始化当前团队成员数组
    public void clearTeam() {
        team = new Programmer[MAX_MEMBER];
        counter=1;
        total=0;
        this.team = team;
    }

    //增加团队成员
    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 (isExist(p)) {
            throw new TeamException("该员工已在本团队中");
        }
        if(!p.getStatus()) {
        	throw new TeamException("该员工已是某团队成员");
        }

        
        int numOfArch = 0, numOfDsgn = 0, numOfPrg = 0;
        for (int i = 0; i < total; i++) {
            if (team[i] instanceof Architect) {numOfArch++;}
            else if (team[i] instanceof Designer){ numOfDsgn++;}
            else if (team[i] instanceof Programmer){ numOfPrg++;}
        }

        if (p instanceof Architect) {
            if (numOfArch >= 1)
            {throw new TeamException("团队中至多只能有一名架构师");}
        } else if (p instanceof Designer) {
            if (numOfDsgn >= 2)
            {throw new TeamException("团队中至多只能有两名设计师");}
        } else if (p instanceof Programmer) {
            if (numOfPrg >= 3)
            {throw new TeamException("团队中至多只能有三名程序员");}
        }
        //添加到数组
        p.setStatus(false);
        p.setMemberId(counter++);
        team[total++] = p;
    }

    //判断成员是否在所创建的团队中
    private boolean isExist(Programmer p) {
        for (int i = 0; i < total; i++) {
            //通过团队的成员比对程序员中的id
            if (team[i].getId() == p.getId()) return true;
        }

        return false;
    }

    //删除指定memberId的程序员
    public void removeMember(int memberId) throws TeamException {
        int n = 0;
        //找到指定memberId的员工,并删除
        for (; n < total; n++) {
            if (team[n].getMemberId() == memberId) {
                team[n].setStatus(true);
                break;
            }
        }
        //如果遍历一遍,都找不到,则报异常
        if (n == total)
            throw new TeamException("找不到该成员,无法删除");
        //后面的元素覆盖前面的元素
        for (int i = n + 1; i < total; i++) {
            team[i - 1] = team[i];
        }
        team[--total] = null;
    }
}

开发项目调度模块主界面
在这里插入图片描述

ProjectService业务层:项目的操作类

pro: Arraylist 用来存项目的集合
count: int = 1 添加项目的标号
addProject(): 新项目添加
dealingPro (Programmer[] team) 项目分配团队开发
showPro() 查看项目当前状态、
delPro(int id) 删除选择的项目

package com.team.service;

import com.team.domain.Employee;
import com.team.domain.Programmer;
import com.team.domain.Project;
import com.team.view.TSUtility;
import com.team.view.TeamView;

import java.util.ArrayList;
import java.util.Random;

/**
 * @description:项目相关模块操作 项目参考:
 * 1.小米官网:开发完成类似于小米官网的web项目
 * 2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城,以商城B2C模式运营的公益在线商城。
 * 3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!使用了轻量级 mvc 框架Blade开发,默认主题使用了漂亮的pinghsu。
 * 4.在线协作文档编辑系统:多人在线协作文档编辑器是一个很常用的功能,适合小组内的文档编辑。
 */
/*
pro: Arraylist<Project> 用来存项目的集合
count: int = 1 添加项目的标号
addProject(): 新项目添加
dealingPro (Programmer[] team) 项目分配团队开发
showPro() 查看项目当前状态、
delPro(int id) 删除选择的项目
*/
public class ProjectService extends Project {
    private ArrayList<Project> pro = new ArrayList<>();
    private TeamView teamView = new TeamView();
    private int count = 1;

    //添加项目1
    public void addProject() throws InterruptedException {
        AddTo();
    }

    //添加项目2
    public void AddTo() throws InterruptedException {
        System.out.println("项目参考:--------------------------------------------------");
        System.out.println("1.小米官网:开发完成类似于小米官网的web项目.");
        System.out.println("2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城.");
        System.out.println("3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!");
        System.out.println("4.在线协作文档编辑系统:一个很常用的功能,适合小组内的文档编辑。");
        System.out.println("5.考情状态系统:通过考情打卡来展现每个人的上班情况");
        System.out.println("------------------------------------------------------------");
        TSUtility.readReturn();
        System.out.println("请输入你想添加的项目名: ");
        char c = TSUtility.readMenuSelectionPro();
        switch (c) {
            case '1':
                Project p1 = new Project();
                p1.setProId(count++);
                p1.setProName("小米官网");
                p1.setDesName("开发完成类似于小米官网的web项目.");
                pro.add(p1);
                TSUtility.loadSpecialEffects();
                System.out.println("已添加项目:" + p1.getProName());
                break;
            case '2':
                Project p2 = new Project();
                p2.setProId(count++);
                p2.setProName("公益在线商城");
                p2.setDesName("猫宁Morning公益商城是中国公益性在线电子商城.");
                pro.add(p2);
                TSUtility.loadSpecialEffects();
                System.out.println("已添加项目:" + p2.getProName());
                break;
            case '3':
                Project p3 = new Project();
                p3.setProId(count++);
                p3.setProName("博客系统");
                p3.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
                pro.add(p3);
                TSUtility.loadSpecialEffects();
                System.out.println("已添加项目:" + p3.getProName());
                break;
            case '4':
                Project p4 = new Project();
                p4.setProId(count++);
                p4.setProName("在线协作文档编辑系统");
                p4.setDesName("一个很常用的功能,适合小组内的文档编辑。");
                pro.add(p4);
                TSUtility.loadSpecialEffects();
                System.out.println("已添加项目:" + p4.getProName());
                break;
            case '5':
                Project p5 = new Project();
                p5.setProId(count++);
                p5.setProName("考情状态系统");
                p5.setDesName("通过考情打卡来展现每个人的上班情况.");
                pro.add(p5);
                TSUtility.loadSpecialEffects();
                System.out.println("已添加项目:" + p5.getProName());
                break;
            default:
                System.out.println("项目不存在");
                break;
        }
    }

    //给项目分配团队
    public void dealingPro(Programmer[] team) {
        ArrayList<Programmer[]> team1 = teamView.getTeam();
        //随机分配项目
        /*      Random ra = new Random();
        int ranNum = ra.nextInt(pro.size());
        Project project = this.pro.get(ranNum);

        project.setTeamName(teamName);
        project.setTeam(team);
        project.setStatus(true);

        pro.set(ranNum,project);*/
        if (pro.size() == 0) {
            System.out.println("当前没有项目,请重新添加!");
        } else {
            System.out.println("当前团队有人员:");
            for (int i = 0; i < team.length; i++) {
                System.out.println(team[i]);
            }
            System.out.println("请为当前团队创建一个团队名称:");
            String teamName = TSUtility.readKeyBoard(6, false);
            Random ra = new Random();
            int ranNum = ra.nextInt(pro.size());
            Project project = this.pro.get(ranNum);
            /*while (project.getStatus()){ //使用while循环,判断如果项目已经开发,重新读取
                ranNum= ra.nextInt(pro.size());//重新获取随机数
                project=this.pro.get(ranNum);//集合重新取出随机项目
            }*/
            project.setTeamName(teamName);
            project.setTeam(team);
            project.setStatus(true);
            pro.set(ranNum, project);
        }
    }

    //查看目前项目情况
    public void showPro() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        try {
            if (pro.size() == 0) {
                throw new Exception();
            } else {
                for (int i = 0; i < pro.size(); i++) {
                    System.out.println(pro.get(i));
                    Project p = pro.get(i);
                    System.out.println("项目名【" + p.getProName() + "】,开发状态" + p.isStatus());
                    System.out.println("开发团队----->" + pro.get(i).getTeamName());
                }
            }
        } catch (Exception e) {
            System.out.println("目前没有团队,请重新添加团队,谢谢!!!" + e.getMessage());
        }
    }

    //删除选择的项目
    public void delPro(int id) {
        boolean flag = false;
        for (int i = 0; i < pro.size(); i++) {
            if (pro.get(i).getProId() == id) {
                pro.remove(i);
                for (i = id; i <= pro.size(); i++) {
                    pro.get(i - 1).setProId(pro.get(i - 1).getProId() - 1);
                }
                flag = true;
            }
        }
        if (flag) {
            System.out.println("删除成功!");
            count--;
        } else {
            try {
                throw new TeamException("该项目不存在");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }
    }

    //得到所有项目数据集合
    public ArrayList<Project> getAllPro() {
        return pro;
    }

}

public void DevelopmentsProbject(ArrayList<Programmer[]> manyTeam) {
        boolean loopFlagThr = true;
        char keyThr = 0;
        do {
            System.out.println("-----------------------------------------------------------");
            System.out.print(ANSI_RESET + ANSI_GREEN);
            System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");
            System.out.println("🔣                                  🔣");
            System.out.println("🔣         ~开发项目调度模块~          🔣");
            System.out.println("🔣                                  🔣");
            System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");
            System.out.println("🔣          ~开发项目管理主菜单~       🔣");
            System.out.println("🐕1.          <项目的添加>            *");
            System.out.println("🐖2.        <项目分配开发团队>         *");
            System.out.println("🐱3.          <项目的查看>            *");
            System.out.println("🐂4.          <项目的删除>            *");
            System.out.println("🐇5.         <退出当前菜单>           *");
            System.out.println("    ⬇请选择:  ");
            System.out.print(ANSI_RESET + ANSI_YELLOW);
            keyThr=TSUtility.readMenuSelectionPro();
            System.out.println("-----------------------------------------------------------");
            switch (keyThr) {
                //项目的添加
                case '1':
                    try {
                        projectSer.addProject();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    break;
                //项目分配开发团队
                case '2':
                    for (Programmer[] pro : manyTeam) {
                        projectSer.dealingPro(pro);
                    }
                    break;
                //项目的查看
                case '3':
                    try {
                        projectSer.showPro();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    break;
                case '4':
                //项目的删除
                    System.out.println("请输入需要删除的项目id:");
                    int j  = TSUtility.readInt();
                    projectSer.delPro(j);
                    break;
                //退出
                case '5':
                    System.out.print("确认是否退出(Y/N):");
                    char yn = TSUtility.readConfirmSelection();
                    if (yn == 'Y') {
                        loopFlagThr = false;
                    }
                    break;
                default:
                    System.out.println("输入有误!请重新输入!");
                    break;
            }
        } while (loopFlagThr);
    }

总结

在编写代码的过程中,运行代码,测试功能的过程中会出现非常多的BUG
比如:
在开发人员的修改以及添加后,在团队添加成员中无法互通;

随机分配开发团队中,利用TeamView视图层获取到当前团队数量通过数组的形式,然而里面的每个团队有通过类标的形式显示团队成员,最后再随机分配团队。不过这里会产生bug,该bug就是如果在ProbjectService业务层中对随机分配团队的代码执行while语句判断开发状态是否为true时,这里会产生死循环,如果只有一个项目,而团队只有一个,每一次分配都要重新分配团队名称,对于分配了的项目,程序还会一致判定为true,导致会一直寻找,变成死循环;
当然,随机分配不一定所有的项目都分配到开发团队,有的可能就没分配到。
项目开发情况查看:如果团队被随机分配,没有bug后,开发状态以及被谁开发,会通过此显示出来。

看到这里了,就给作者一个小小的点赞,历时一个星期的项目!!!!!!!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值