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

news/2024/10/18 18:13:21/

项目目标

模拟实现一个基于文本界面的《项目开发团队分配管理软件》。

通过该项目,熟悉Java面向对象的特性,可以进一步掌握编程和调试的技巧。

项目的系统功能结构如下图所示:

系统流程图如下图所示:

项目需求

  • 软件启动时,首先进入登录界面进行注册、登录功能

  • 登陆成功后,进入主菜单

  • 可以修改注册时的用户名和密码

  • 对开发人员的信息进行增删改查操作

  • 人员信息添加完成后,可以根据现有的成员,创建开发团队

  • 创建开发团队过程中,包括基于已有的人员信息添加团队的成员,或删除团队中的某位成员,还可以列出当前已在团队中的成员的列表

  • 团队创建完成后就可以进入项目模块,添加项目后,分配给开发团队进行开发

设计结构

该软件由view、service和domain三个模块组成

view模块:主控模块,负责各种功能的菜单显示以及处理用户的操作

service模块:该模块为实体类的管理模块,处理功能的逻辑上的业务

domain模块:管理实体类对象

项目实现

daomin模块中包含的所有实体类

Employee(雇员)、Programmer(程序员)、Designer(设计师)、Architect(架构师)、 PC(台式电脑)、NoteBook(笔记本电脑)、Printer(打印机)、project(项目)

还有一个接口(interface):Equipment(电子设备)

public interface Equipment {String getDescription();
}

实体类中的继承关系为:

Programmer extends Employee
Designer extends Programmer
Architect extends Designer

其中程序员(Programmer)及其子类均会领取某种电子设备(Equipment)

所以PC(台式电脑)、NoteBook(笔记本电脑)、Printer(打印机)都实现了Equipment(电子设备)这个接口

Equipment接口及其实现子类的设计

  • 说明:

  • model:表示机器型号

  • display:表示显示器名称

  • typ:表示机器的型号

  • 根据各个类中的属性提供get/set方法以及重载构造器

  • 实现类实现接口方法,返回各自的属性信息

Employee类及其子类的设计

  • 说明:

  • memberId: 用来记录成员加入开发团队后在团队中的ID

  • Status:是项目中人员的状态,先赋值为true,当添加到团队时为false

  • equipment :表示该成员领用的设备

  • bonus :表示奖金

  • stock :表示公司奖励的股票数量

  • 可根据需要为类提供各属性的get/set方法以及重载构造器

项目的主体架构如下:

NameListService类的设计

  • 说明:

  • getAllEmployees ()方法:获取当前所有员工。

  • 返回:包含所有员工集合

  • getEmployee(id : int)方法:获取指定ID的员工对象。

  • 参数:指定员工的ID

  • 返回:指定员工对象

  • 异常:找不到指定的员工

  • 在service子包下提供自定义异常类:TeamException

NameListService类的实现

实现员工的添加(根据职业添加(无,程序员,设计师,架构师))

实现员工的修改(至少修改员工的姓名,年龄,工资)

实现员工的删除(注意员工id需要动态显示,也就是删除后,员工id需要更新)

实现员工的查看 (显示所有数据)

public class NameListService {//用来装员工的数据集合private ArrayList<Employee> employees = new ArrayList<>();//添加员工的idprivate 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 (int i = 0; i < employees.size(); i++) {if (employees.get(i).getId() == id) {return employees.get(i);}}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());if (c.equals("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();} else if (c.equals("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();} else if (c.equals("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();} else {//架构师 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("请输入当前架构师的股票:");Integer stock = TSUtility.readstock();Architect architect = new Architect(++count, name, age, salary, printer, bonus, stock);employees.add(architect);System.out.println("人员添加成功!");TSUtility.readReturn();}}//员工的删除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) {System.out.println(e.getMessage());}}}//员工的查看public void showEmployee() throws InterruptedException {TSUtility.loadSpecialEffects();System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");for (int i = 0; i < employees.size(); i++) {System.out.println(" " + employees.get(i));}}//员工的修改 (目前只修改姓名,年龄,工资即可)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) {System.out.println(e.getMessage());}}}
}

用户注册和登录模块的实现

  • 定义一个LoginView类

  • 实现注册方法

  • 如果没有账户则需要注册

  • 如果有账号则直接进行登录

  • 实现登录功能

  • 判断用户输入的值是否正确

  • 如果正确则进入软件菜单

  • 如果错误则重新输入,限制次数只有5次,超过次数则程序停止,重新启动

  • 实现修改用户密码功能

  • 可以实现对用户名,密码,或者两者都可以进行修改即可。

public class LoginView {//首先给定属性:登录用户和密码private String userName = "";private String password = "";//注册功能public void regist() throws InterruptedException {TSUtility.loadSpecialEffects();System.out.println("开始注册:");Scanner sc = new Scanner(System.in);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 || count <= 0) {count = 5;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("登录次数不足!退出!");login();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 password = TSUtility.readKeyBoard(8, false);this.password = password;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.password = password;System.out.println("修改成功!");}else if (options.equals("4")) {System.out.println("退出中");TSUtility.loadSpecialEffects();flag = false;}else  {System.out.println("输入错误!请输入“1”或者“2”或者“3”或者“4”:");}}}
}

ProjectService类的实现

public class ProjectService {private ArrayList<Project> pro=new ArrayList<>();private int count=1;//添加项目public void  addProject() 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("------------------------------------------------------------");TSUtility.readReturn();System.out.println("请输入你想添加的项目名: ");char c = TSUtility.readMenuSelection();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;default:System.out.println("项目不存在");break;}}//给项目分配团队public void dealingPro(Programmer[] team){if (pro.size() == 0) {System.out.println("当前没有项目可分配,请先添加项目");} else {System.out.println("当前团队有人员:");for (int i = 0; i < team.length; i++) {System.out.println(team[i]);}team.equals(team);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);project.setTeamName(teamName);project.setTeam(team);project.setStatus(true);pro.set(ranNum,project);}}//查看目前项目情况public void showPro() throws InterruptedException {TSUtility.loadSpecialEffects();for (int i = 0; i < pro.size(); i++) {System.out.println("项目号 "+pro.get(i).getProId() +" 项目名 "+pro.get(i).getProName() +" 项目描述:" + pro.get(i).getDesName());if (pro.get(i).getTeamName() == null) {System.out.println("项目【"+pro.get(i).getProName() +"】------>未被开发");} else {System.out.println("项目【"+pro.get(i).getProName() +"】开发中......开发团队:" + pro.get(i).getTeamName());}}}//删除选择的项目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) {System.out.println(e.getMessage());}}}//得到所有项目数据集合public ArrayList<Project> getAllPro() {return pro;}
}

开发团队调度模块的实现

TeamService类的设计

功能:关于开发团队成员的管理:添加、删除等

  • 说明:

  • counter为静态变量,用来为开发团队新增成员自动生成团队中的唯一ID,即memberId。(提示:应使用增1的方式)

  • MAX_MEMBER:表示开发团队最大成员数

  • team数组:用来保存当前团队中的各成员对象

  • total:记录团队成员的实际人数

  • getTeam()方法:返回当前团队的所有对象

  • 返回:包含所有成员对象的数组,数组大小与成员人数一致

  • addMember(e: Employee)方法:向团队中添加成员

  • 参数:待添加成员的对象

  • 异常:添加失败, TeamException中包含了失败原因

  • removeMember(memberId: int)方法:从团队中删除成员

  • 参数:待删除成员的memberId

  • 异常:找不到指定memberId的员工,删除失败

在TeamService中抛出自定义异常

  • 失败信息包含以下几种: (需要抛出自定义异常)

  • 成员已满,无法添加

  • 该成员不是开发人员,无法添加

  • 该员工已在本开发团队中

  • 该员工已是某团队成员

  • 团队中至多只能有一名架构师(以下判断可借用instanceof进行判断)

  • 团队中至多只能有两名设计师

  • 团队中至多只能有三名程序员

public class TeamService {//用于自动生成团队成员的memberIdprivate 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++) {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;}
}
  1. 团队界面显示公司成员的列表

//列出公司所用成员
System.out.println("------------开发团队调度-------------");
System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
//用增强for循环实现
for (Employee emp : listSvc.getAllEmployees()) {System.out.println(emp);
}

TeamView类的设计

说明:

listSvc和teamSvc属性:供类中的方法使用

enterMainMenu ()方法:主界面显示及控制方法。

以下方法仅供enterMainMenu()方法调用:

listAllEmployees ()方法:以表格形式列出公司所有成员

getTeam()方法:显示团队成员列表操作

addMember ()方法:实现添加成员操作

deleteMember ()方法:实现删除成员操作

public class TeamView {private TeamService teamSvc = new TeamService();private NameListService listSvc = new NameListService();private ArrayList<Programmer[]> teamList = new ArrayList<>();public ArrayList<Programmer[]> getManyTeam() throws TeamException {boolean flag = true;char key = 0;while (flag) {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'://列出公司所有成员System.out.println("----------------------------------开发团队调度----------------------------------");System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");for (Employee emp : listSvc.getAllEmployees()) {System.out.println(emp);}enterMainMenu();break;case '2':System.out.println("----------------团队列表-----------------");for (Programmer[] team : teamList) {for (int i = 0; i < team.length; i++) {System.out.println(team[i]);}System.out.println("---------------------------------------");}break;case '3':System.out.println("请输入想要删除第几个团队");boolean flag1 = true;while (flag1) {int num = TSUtility.readInt();if (num <= 0) {System.out.println("输入错误,请重新输入:");continue;}else if (num <= teamList.size()) {System.out.print("确认是否删除(Y/N):");char de = TSUtility.readConfirmSelection();if (de == 'Y') {//修改状态Programmer[] t = teamList.get(num-1);for (int i = 0; i < teamList.get(num-1).length; i++) {t[i].setStatus(true);}teamList.remove(num - 1);}} else {System.out.println("没有该团队,请正常输入!" + "目前团队只有" + teamList.size() + "个");}flag1 = false;}break;case '4':System.out.print("确认是否退出(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'Y') {flag = false;}break;default:break;}}return teamList;}public void enterMainMenu() throws TeamException {boolean loopFlagSec = true;char keySec2 = 0;do {System.out.println("------------------------------------------------------------------------------");System.out.print("1-团队列表  2-添加团队成员  3-删除团队成员  4-退出  请选择(1-4):");keySec2 = TSUtility.readMenuSelection();switch (keySec2) {case '1'://团队列表TeamList();break;case '2'://添加团队成员AddTeam();break;case '3'://删除团队成员DelTeam();break;case '4'://退出System.out.print("确认是否退出(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'Y') {teamList.add(teamSvc.getTeam());teamSvc.clearTeam();loopFlagSec = false;}break;}} while (loopFlagSec);}public void TeamList() {int count = 0;System.out.println("-------------------团队成员表-------------------");System.out.println("TID/ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");for (Employee employee : teamSvc.getTeam()) {count++;System.out.println(" " + count + "/" + employee + " ");}}public void AddTeam() throws TeamException {//列出公司所有成员System.out.println("-------------------------人员表-------------------------");System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");for (Employee emp : listSvc.getAllEmployees()) {System.out.println(emp);}System.out.println("----------添加团队成员----------");System.out.print("请输入添加的团队员工的ID:");int id = TSUtility.readInt();int ber = -1;//判断id是否存在for (int i = 0; i < listSvc.getAllEmployees().size(); i++) {if (listSvc.getAllEmployees().get(i).getId() == id) {ber = id;break;}}if (ber == -1) {System.out.println("不存在该id的开发人员!");} else {//获取集合中的元素信息Employee e = listSvc.getAllEmployees().get(id-1);teamSvc.addMember(e);System.out.println("添加成功");}}public void DelTeam() throws TeamException {System.out.println("----------删除团队成员----------");System.out.print("请输入删除团队员工的TID:");int removeId = TSUtility.readInt();teamSvc.removeMember(removeId);}
}

程序运行主界面类IndexView的实现

将上述的四个模块的内容整合到一起,运行程序并调试bug

public class IndexView {/*** 颜色特效*/public static final String ANSI_RESET = "\u001B[0m";public static final String ANSI_GREEN = "\u001B[32m";public static final String ANSI_YELLOW = "\u001B[33m";public static final String ANSI_PURPLE = "\u001B[35m";public static final String ANSI_BLUE = "\u001B[34m";public static final String ANSI_CYAN = "\u001B[36m";private LoginView loginVi = new LoginView();private NameListService nameListSer = new NameListService();private TeamView teamVi = new TeamView();private ProjectService projectSer = new ProjectService();private ArrayList<Programmer[]> manyTeam=null;public  void menu() {boolean loopFlag = true;char key = 0;System.out.println(ANSI_PURPLE);System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");System.out.println("🔣                                   🔣");System.out.println("🔣    欢迎来到项目开发团队分配管理软件    🔣");System.out.println("🔣                                   🔣");System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣");System.out.println("🐕");System.out.println("🐕");System.out.println("🐕");System.out.println("🐕-----------<请您先进行登录>-------------🐕");TSUtility.readReturn();try {loginVi.login();} catch (InterruptedException e) {e.printStackTrace();}do {System.out.println(ANSI_RESET + ANSI_CYAN);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);key = TSUtility.readMenuSelectionPro();switch (key) {case '1':try {loginVi.update();} catch (InterruptedException e) {e.printStackTrace();}break;case '2':try {nameListSer.showEmployee();} catch (InterruptedException e) {e.printStackTrace();}boolean loopFlagSec = true;char keySec = 0;do {System.out.print(ANSI_RESET + ANSI_YELLOW);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("⬇请选择:  ");keySec=TSUtility.readMenuSelectionPro();switch (keySec) {case '1':try {nameListSer.addEmployee();} catch (InterruptedException e) {e.printStackTrace();}break;case '2':try {nameListSer.showEmployee();} catch (InterruptedException e) {e.printStackTrace();}break;case '3':System.out.println("请输入需要修改的员工id:");int i = TSUtility.readInt();try {nameListSer.modifyEmployee(i);} catch (InterruptedException e) {e.printStackTrace();}break;case '4':System.out.println("请输入需要删除的员工id:");int j  = TSUtility.readInt();nameListSer.delEmployee(j);break;case '5':System.out.print("确认是否退出(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'Y') {loopFlagSec = false;}break;default:System.out.println("输入有误!请重新输入!");break;}} while (loopFlagSec);break;case '3':System.out.println(ANSI_BLUE);try {manyTeam = teamVi.getManyTeam();} catch (TeamException e) {System.out.println(e.getMessage());}TSUtility.readReturn();break;case '4':boolean loopFlagThr = true;char keyThr = 0;do {System.out.print(ANSI_RESET + ANSI_GREEN);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();switch (keyThr) {case '1':try {projectSer.addProject();} catch (InterruptedException e) {e.printStackTrace();}break;case '2':if (manyTeam == null) {System.out.println("当前没有团队!");} else {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);break;case '5':System.out.print("确认是否退出(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'Y') {loopFlag = false;}break;default:break;}} while (loopFlag);}public static void main(String[] args) {new IndexView().menu();}
}

总结

在运行时输入错误信息抛出来的异常带有其他详细信息,观察代码后发现没有将catch里的printStackTrace()改为getMessage()。因为printStackTrace()是将捕获到的异常信息完整的输入在控制台上,而getMessage()是返回此 throwable 的详细消息字符串。

在给项目分配团队时,会给已分配团队的项目再次分配,改进的方法是在为项目分配团队是进行判断,遍历项目查看是否已近被分配团队了,如果没有,就为它分配;如果已分配就直接跳出,不在进入分配;

代码如下:

boolean f = false;for (Project p : projects) {//判断项目的状态//1.1项目状态为false未分配,进入if判断,将true赋值给f//2.1项目状态为true已分配,不进入if判断,此时f的值为falseif (!p.isStatus()) {  f = true;break;}//1.2现在f的值为true,不进入if判断,进入增强for循环为项目分配团队//2.2f为false,进入if,执行return,结束方法,不进入增强for循环if (!f) {System.out.println("没有项目未被分配");return;}}for (Programmer[] programmers : manyTeam) {projectSer.dealingPro(programmers);}

在开发过程中还经常遇到的一些小问题,比如:空指针、索引越界等等,还需要多多的积累。


http://www.ppmy.cn/news/330577.html

相关文章

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

目录 1. 项目需求&#xff1a; 2. 项目的结构图&#xff08;mvc&#xff09;&#xff1a; 3.部分效果展示&#xff1a; 4. 项目的整体思路&#xff1a; 4.1 实体类及数据存储 4.2 界面类 4.3 服务类 5.项目代码及部分解释&#xff1a; 5.1 代码结构图&#xff1a;​编辑 5…

Java面向对象实践--开发团队调度软件

开发团队调度软件 前言开发团队调度软件一、需求说明1.添加成员2.开发团队人员组成要求3.添加失败显示原因 二、软件设计架构Equipment接口及其实现子类的设计Employee类及其子类的设计Status类NameListService类的设计TeamService类的设计TeamView类的设计 三、代码实现项目结…

Java学习笔记——正则表达式(Pattern类、Matcher类和PatternSyntaxException)

目录 一、Pattern类 &#xff08;一&#xff09;Pattern 介绍 &#xff08;二&#xff09;Pattern 方法 二、Matcher类 &#xff08;一&#xff09;Matcher 类介绍 &#xff08;二&#xff09;Matcher 类方法 三、PatternSyntaxException 四、代码 Java中与正则表达式…

佳能MOV视频恢复方法

随着佳能机器的普及以及用户使用量越来越大&#xff0c;佳能机器在使用过程中则容易出现各种情况的数据丢失以及录制过程中断电导致的损坏&#xff0c;因为佳能机器在录制过程中会产生不连续存储&#xff0c;所以数据出现丢失之后&#xff0c;市面上普通的恢复软件都无法直接恢…

【MySQL学习笔记】update,delete,select语句

1.SQL语句 1.1 UPDATE UPDATE更新原表中的各列 SET修改哪列和要赋什么值&#xff0c; WHERE指定修改哪行&#xff0c;没写WHERE则更新所有行 UPDATE employee SET salary WHERE user_name #更新多个列&#xff0c;逗号隔开 UPDATE employee SET salary 100,emp_email …

【算法系列 | 5】深入解析排序算法之——快速排序

序言 你只管努力&#xff0c;其他交给时间&#xff0c;时间会证明一切。 文章标记颜色说明&#xff1a; 黄色&#xff1a;重要标题红色&#xff1a;用来标记结论绿色&#xff1a;用来标记一级论点蓝色&#xff1a;用来标记二级论点 决定开一个算法专栏&#xff0c;希望能帮助大…

【LINGO】求七个城市最小连线图,使天然气管道价格最低

目录 1、问题描述 2、问题求解 1、问题描述 2、问题求解 model: sets: cities/A,B1,B2,C1,C2,C3,D/; roads(cities,cities)/A B1,A B2,B1 C1,B1 C2,B1 C3,B2 C1, B2 C2,B2 C3,C1 D,C2 D,C3 D/:w,x; endsets data: w2 4 3 3 1 2 3 1 1 3 4; enddata nsize(cities); !城市的个数…

Forexclub认为针对俄的天然气价格上限可能只是摆设

欧盟能源监管机构合作署(ACER)负责人告诉英国《金融时报》&#xff0c;欧盟对天然气的价格上限是一个未经测试的工具&#xff0c;可能无法阻止欧洲家庭和企业的天然气价格飙升&#xff0c;可能只是摆设。 Forexclub认为天然气价格的上限是难以理解的&#xff0c;不符合市场需求…