系统功能结构
系统流程:
目 标
模拟实现一个基于文本界面的《项目开发团队分配管理软件》 熟悉Java面向对象的高级特性,进一步掌握编程技巧和调试技巧 主要涉及以下知识点:
- 类的继承性和多态性
- 对象的值传递、接口
- static和final修饰符
- 特殊类的使用:包装类、抽象类、内部类
- 异常处理
- Java基本语法和流程控制
- 数组,ArrayList集合
需求说明
该软件实现以下功能:
- 软件启动时,首先进入登录界面进行注册和登录功能。
- 当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。
- 然后可以对开发人员进行增删改操作 人员添加成功后,根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目。
- 组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。
- 团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。
软件设计结构
该软件由以下三个模块组成:
- com.team.view 模块为主控模块,负责菜单的显示和处理用户操作
- com.team.service 模块为实体对象(Employee及其子类如程序员等)的管理模块, NameListService和TeamService类分别用各自的数组来管理公司员工和开发团队成员对象
- ProjectService是对项目的操作对象类 domain模块为Employee及其子类等JavaBean类所在的包
1.用户注册和登录模块
- 定义一个LoginView类
- 实现注册方法
- 如果没有账户则需要注册
- 如果有账号则直接进行登录
- 实现登录功能
- 判断用户输入的值是否正确
- 如果正确则进入软件菜单
- 如果错误则重新输入,限制次数只有5次,超过次数则程序停止,重新启动
- 实现修改用户密码功能
- 可以实现对用户名,密码,或者两者都可以进行修改即可。
2.开发人员管理模块
在domain包中完成各个类的实体类创建
软件设计结构
Equipment接口及其实现子类的设计
Employee类及其子类的设计
在NameListService类中完成功能操作
-
实现员工的添加(根据职业添加(无,程序员,设计师,架构师))
-
实现员工的修改(至少修改员工的姓名,年龄,工资)
-
实现员工的删除(注意员工id需要动态显示,也就是删除后,员工id需要更新)
-
实现员工的查看 (显示所有数据)
NameListService类的设计
- 按照设计要求编写NameListService类
- 一个属性为:private ArrayList<Employee> employees
- 有一个代码块用作数据的填充(注意不同人的身份和设备都不同)
- 有一个方法:getAllEmployees(),返回employees对象即可
- 还有一个方法:getEmployee(int id),得到指定id的员工,没有则抛出自定义的异常。
- 其他方法
3.开发团队调度管理模块
需求说明
TeamService类的设计
TeamView类的设计
4.开发项目管理模块
IndexView类的设计
部分参考代码:
IndexView
package com.guanqia12.view;
import com.guanqia12.domain.Programmer;
import com.guanqia12.service.NameListService;
import com.guanqia12.service.ProjectService;
import com.guanqia12.service.TeamException;
import java.util.Scanner;
//项目运行主界面
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 ProjectService projectSer = new ProjectService();
private TeamView teamVi = new TeamView(nameListSer,projectSer);
public static void main(String[] args) throws InterruptedException, TeamException {
IndexView i = new IndexView();
i.menu();
}
public void menu() throws InterruptedException, TeamException {
Scanner sc = new Scanner(System.in);
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':
loginVi.update();
break;
case '2':
boolean loopFlagSec = true;
char keySec = 0;
nameListSer.showEmployee();
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':
nameListSer.addEmployee();
break;
case '2':
nameListSer.showEmployee();
break;
case '3':
System.out.println("请输入需要修改的员工id");
int i1 = sc.nextInt();
nameListSer.modifyEmployee(i1);
break;
case '4':
System.out.println("请输入需要删除的员工id");
int i = sc.nextInt();
nameListSer.delEmployee(i);
break;
case '5':
TSUtility.loadSpecialEffects();
loopFlagSec = false;
break;
}
} while (loopFlagSec);
break;
case '3':
teamVi.developmentTeam();
break;
case '4':
/*boolean loopFlagThr = true;
while (loopFlagThr) {
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("请选择:");
char keyThr = TSUtility.readMenuSelectionPro();
switch (keyThr) {
case '1':
p.addProject();
break;
case '2':
if (t.team.size() == 0) {
System.out.println("没有团队!");
} else {
for (Programmer[] pro : t.team) {
p.dealingPro(pro);
}
}
if (p.p.size() > t.team.size()) {
System.out.println("还有项目没有分配团队!");
}
if (p.p.size() == t.team.size()) {
System.out.println("项目已完成分配!");
}
if (p.p.size() < t.team.size()) {
System.out.println("还有团队没有分配项目!");
}
break;
case '3':
try {
p.showProject();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case '4':
System.out.println("请输入需要删除的项目id:");
int j = TSUtility.readInt();
p.delProject(j);
break;
case '5':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagThr = false;
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
}
break;*/
boolean loopFlagThr = true;
while (loopFlagThr) {
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("请选择:");
char keyThr = TSUtility.readMenuSelectionPro();
switch (keyThr) {
case '1':
try {
projectSer.addProject();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case '2':
if (teamVi.team.size() == 0) {
System.out.println("没有团队!");
} else {
for (Programmer[] pro : teamVi.team) {
projectSer.dealingPro(pro);
}
}
if (projectSer.p.size() > teamVi.team.size()) {
System.out.println("还有项目没有分配团队!");
}
if (projectSer.p.size() == teamVi.team.size()) {
System.out.println("项目分配成功!");
}
if (projectSer.p.size() < teamVi.team.size()) {
System.out.println("还有团队没有分配项目!");
}
break;
case '3':
try {
projectSer.showProject();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case '4':
System.out.println("请输入需要删除的项目id:");
int j = TSUtility.readInt();
projectSer.delProject(j);
break;
case '5':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagThr = false;
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
}
break;
case '5':
System.out.print("确认是否退出(Y/N):");
char y = TSUtility.readConfirmSelection();
if (y == 'Y') {
loopFlag = false;
}
break;
default:
break;
}
} while (loopFlag);
}
public ProjectService getP() {
return projectSer;
}
}
LoginView
package com.guanqia12.view;
import java.util.Scanner;
import static com.guanqia12.view.IndexView.ANSI_RESET;
//登录主界面
public class LoginView {
private String userName = "";
private String passWord = "";
private int count = 4;
public LoginView() {
}
//登录
public void Login() throws InterruptedException {
System.out.println(ANSI_RESET);
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 == "" && this.passWord == "") {
System.out.println("未找到该用户,请先注册!");
regist();
} else if (this.userName.equals(userName) && this.passWord.equals(passWord)) {
TSUtility.loadSpecialEffects();
System.out.println("登录成功!欢迎您:" + userName);
} else {
if (count <= 0) {
System.out.println("您的账户已被锁定,请与管理员联系!");
System.exit(0);
} else {
System.out.println("登录失败!用户名和密码不匹配!");
System.out.println("登录次数还剩" + count + "次,请重新输入:");
count--;
Login();
}
}
}
//注册
public void regist() throws InterruptedException {
TSUtility.loadSpecialEffects();
System.out.println("开始注册:");
System.out.println("请输入你的账户注册名称:");
this.userName = TSUtility.readKeyBoard(4, false);
System.out.println("请输入你的注册密码:");
this.passWord = TSUtility.readKeyBoard(8, false);
System.out.print("注册成功!请登录!");
Login();
}
//修改
public void update() throws InterruptedException {
boolean flag=true;
char key=0;
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);
key = TSUtility.readMenuSelectionPro();
switch (key){
case '1':
System.out.println("请输入你的修改的账户名称:");
String userName = TSUtility.readKeyBoard(4, false);
this.userName = userName;
System.out.println("修改成功!");
break;
case '2':
System.out.println("请输入你的修改密码:");
String passWord = TSUtility.readKeyBoard(8, false);
this.passWord = passWord;
System.out.println("修改成功!");
break;
case '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("修改成功!");
break;
case '4':
System.out.println("选择是否退出(Y/N):");
char c = TSUtility.readConfirmSelection();
if (c=='Y') {
flag = false;
}
break;
default:
System.out.println("输入错误!没有该选项");
}
}
}
}
TeamView
package com.guanqia12.view;
import com.guanqia12.domain.Employee;
import com.guanqia12.domain.Programmer;
import com.guanqia12.domain.Project;
import com.guanqia12.service.NameListService;
import com.guanqia12.service.ProjectService;
import com.guanqia12.service.TeamException;
import com.guanqia12.service.TeamService;
import java.util.ArrayList;
import java.util.Scanner;
import static com.guanqia12.view.TSUtility.readKeyBoard;
public class TeamView extends NameListService {
private Scanner sc = new Scanner(System.in);
private TeamService teamSvc = new TeamService();
private NameListService listSvc = null;
private ProjectService projectSer = null;
public ArrayList<Programmer[]> team = new ArrayList<>();
public TeamView() {
}
public TeamView(NameListService listSvc, ProjectService projectSer) {
this.listSvc = listSvc;
this.projectSer = projectSer;
}
public void enterMainMenu() throws TeamException, InterruptedException {
boolean b = true;
listAllEmployees();//显示员工成员列表
while (b) {
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出");
System.out.print("请选择(1-4):");
char c = TSUtility.readMenuSelection();
switch (c) {
case '1':
getTeam();
break;
case '2':
//显示员工成员列表
listAllEmployees();
addMember();
listAllEmployees();
break;
case '3':
getTeam();//团队列表
deleteMember();
break;
case '4':
System.out.print("确认是否退出(Y/N):");
char c1 = TSUtility.readConfirmSelection();
if (c1 == 'Y') {
//在集合中添加一个团队
team.add(teamSvc.getTeam());
//格式化团队
teamSvc.clearTeam();
b = false;
}
break;
}
}
}
public void listAllEmployees() throws InterruptedException {
System.out.println("\n-----------------开发团队调度软件-------------------\n");
ArrayList<Employee> allEmployees = listSvc.getAllEmployees();
if (allEmployees.size() == 0) {
System.out.println("没有员工信息!");
} else {
listSvc.showEmployee();
}
}
public void getTeam() {
System.out.println("------------------团队成员列表------------------");
//获取team中所有程序员构成的数组
Programmer[] team = teamSvc.getTeam();
if (team.length == 0) {
System.out.println("开发团队目前没有成员!");
} else {
System.out.println("TID/ID\t姓名\t\t年龄\t 工资\t 职位\t 奖金\t 股票");
//循环输出团队成员信息
for (int i = 0; i < team.length; i++) {
System.out.println(" " + team[i].getDetailsForTeam());
}
}
System.out.println("----------------------------------------------");
}
public void addMember() {
System.out.println("-------------添加成员-------------");
System.out.println("请输入要添加的员工ID:");
int id = TSUtility.readInt();
int index = -1;
//判断输入的id值是否有意义
for (int i = 0; i < listSvc.getAllEmployees().size(); i++) {
//获取成员集合中的id,看是否存在该id
if (listSvc.getAllEmployees().get(i).getId() == id) {
//找到的id值赋值给index
index = id;
break;
}
}
if (index == -1) {
System.out.println("此id的开发成员不存在");
} else {
//用户输入的值减1
index--;
try {
//获取成员集合中的元素信息
Employee e = listSvc.getAllEmployees().get(index);
//添加
teamSvc.addMember(e);
System.out.println("添加成功");
} catch (TeamException e) {
System.out.println("添加失败," + e.getMessage());
}
}
TSUtility.readReturn();
}
//删除团队成员
private void deleteMember() throws TeamException {
if (teamSvc.getTeam().length == 0) {
System.out.println("当前无任何团队!");
} else {
System.out.println("-------------删除成员-------------");
System.out.println("请输入要删除的员工TID:");
String s = sc.next();
int memberId = TSUtility.readInt();
int index = -1;
//判断输入的id值是否有意义
for (int i = 0; i < teamSvc.getTeam().length; i++) {
if (teamSvc.getTeam()[i].getMemberId() == memberId) {
index = memberId;
break;
}
}
if (index == -1) {
System.out.println("此id的团队成员不存在");
} else {
System.out.print("确认是否删除(Y/N):");
char c = TSUtility.readConfirmSelection();
if (c == 'Y') {
teamSvc.removeMember(index);
System.out.println("删除成功");
} else System.out.println("已取消删除");
}
}
TSUtility.readReturn();
}
//查看团队
public void showTeam() {
System.out.println("-----------团队列表-----------");
if (team.size() == 0) {
System.out.println("当前无团队信息");
System.out.println("-----------------------------");
} else {
//循环团队集合
for (int i = 0; i < team.size(); i++) {
//创建数组,团队集合赋值
Programmer[] t = team.get(i);
//循环集合中的数组
for (int j = 0; j < team.get(i).length; j++) {
//输出数组中的成员列表
System.out.println(t[j]);
}
System.out.println("-----------------------------");
}
}
}
public void deleteTeam() throws InterruptedException {
if (team.size() == 0) {
System.out.println("当前无团队信息!");
} else {
System.out.print("请输入想要删除第几个团队:");
int num = TSUtility.readInt();
if (num <= 0 || num > team.size()) {
System.out.println("输入错误,当前共有" + team.size() + "个团队");
} else {
//输入的值减1
num--;
System.out.print("确认是否删除(Y/N):");
char c = TSUtility.readConfirmSelection();
if (c == 'Y') {
//创建数组,集合中的团队赋值
Programmer[] t = team.get(num);
for (int i = 0; i < team.get(num).length; i++) {
//修改数组中成员的状态值
t[i].setStatus(true);
}
team.remove(num);
System.out.println("团队删除成功!");
System.out.println("该团队是否负责项目(Y/N)");
String s = readKeyBoard(1, false).toUpperCase();
c = s.charAt(0);
if (c == 'Y') {
ArrayList<Project> p = projectSer.getP();
for (Project pp:p){
for (int i = 0; i < p.size(); i++) {
if (!p.get(i).isStatus()) {
System.out.println("项目{项目号='" + p.get(i).getProId() + "'项目名='" + p.get(i).getProName() +
"', 项目描述='" + p.get(i).getDesName() + ".',开发团队名称='" + p.get(i).getTeamName() +
"',开发状态=" + p.get(i).isStatus() + "}");
System.out.println("项目【" + p.get(i).getProName() + "】---> 未被开发!");
} else {
System.out.println("项目{项目号='" + p.get(i).getProId() +" 项目【" + p.get(i).getProName() + "】---> " + "正在被团队" +
p.get(i).getTeamName() + " 开发中!");
}
}
}
System.out.println("请输入该团队负责第几个项目:");
int n = TSUtility.readInt();
projectSer.updateStates((n-1));
} else {
return;
}
} else System.out.println("已取消删除");
}
}
TSUtility.readReturn();
}
//开发团队调度管理模块
public void developmentTeam() throws TeamException, InterruptedException {
boolean b = true;
while (b) {
System.out.println("-----------团队调度界面-----------");
System.out.println("1.添加团队");
System.out.println("2.查看团队");
System.out.println("3.删除团队");
System.out.println("4.退出");
System.out.print("请选择(1-4):");
char c = TSUtility.readMenuSelection();
switch (c) {
case '1':
enterMainMenu();
break;
case '2':
showTeam();
break;
case '3':
deleteTeam();
break;
case '4':
System.out.println("确认退出?(Y/N):");
char c1 = TSUtility.readConfirmSelection();
if (c1 == 'Y') {
b = false;
} else {
System.out.println("已取消退出!");
break;
}
break;
}
}
}
}
NameListService
package com.guanqia12.service;
import com.guanqia12.domain.*;
import com.guanqia12.view.TSUtility;
import java.util.ArrayList;
//开发人员管理
public class NameListService {
private ArrayList<Employee> employees=new ArrayList<>();
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 (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")) {
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")) {
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")) {
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 {
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) {
e.printStackTrace();
}
}
}
//员工的查看
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) {
e.printStackTrace();
}
}
}
}
ProjectService
package com.guanqia12.service;
import com.guanqia12.domain.Programmer;
import com.guanqia12.domain.Project;
import com.guanqia12.view.TSUtility;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class ProjectService {
public ArrayList<Project> p = 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项目.");
p.add(p1);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:" + p1.getProName());
break;
case '2':
Project p2 = new Project();
p2.setProId(count++);
p2.setProName("公益在线商城");
p2.setDesName("猫宁Morning公益商城是中国公益性在线电子商城.");
p.add(p2);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:" + p2.getProName());
break;
case '3':
Project p3 = new Project();
p3.setProId(count++);
p3.setProName("博客系统");
p3.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
p.add(p3);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:" + p3.getProName());
break;
case '4':
Project p4 = new Project();
p4.setProId(count++);
p4.setProName("在线协作文档编辑系统");
p4.setDesName("一个很常用的功能,适合小组内的文档编辑。");
p.add(p4);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:" + p4.getProName());
break;
default:
System.out.println("项目不存在");
break;
}
}
public void dealingPro(Programmer[] team) {
for (Project pp : p) {
boolean status = pp.isStatus();
if (!status) {
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 r = new Random();
int ranNum = r.nextInt(p.size());
Project project = this.p.get(ranNum);
if (!project.isStatus()) {
project.setTeamName(teamName);
project.setTeam(team);
project.setStatus(true);
p.set(ranNum, project);
}
return;
}
}
System.out.println("当前没有待开发项目");
}
public void addProjectTwo() { //新项目添加
Scanner sc = new Scanner(System.in);
System.out.println("请输入新项目名称:");
String projectName = sc.next();
System.out.println("请输入新项目简介:");
String desName = sc.next();
p.add(new Project(count++, projectName, desName, null, null, false));
System.out.println("添加成功");
TSUtility.readReturn();
}
public void showProject() throws InterruptedException { //查看项目当前状态
TSUtility.loadSpecialEffects(); // 请稍等加载中
if (p.size() == 0) {
System.out.println("还没有项目,请先添加");
return;
}
for (int i = 0; i < p.size(); i++) {
if (!p.get(i).isStatus()) {
System.out.println("项目{项目号='" + p.get(i).getProId() + "'项目名='" + p.get(i).getProName() +
"', 项目描述='" + p.get(i).getDesName() + ".',开发团队名称='" + p.get(i).getTeamName() +
"',开发状态=" + p.get(i).isStatus() + "}");
System.out.println("项目【" + p.get(i).getProName() + "】---> 未被开发!");
} else {
System.out.println("项目【" + p.get(i).getProName() + "】---> " + "正在被团队" +
p.get(i).getTeamName() + " 开发中!");
}
}
}
//删除项目
public void delProject(int id) {
boolean flag = false;
for (int i = 0; i < p.size(); i++) {
if (p.get(i).getProId() == id) {
p.remove(i);
for (i = id; i <= p.size(); i++) {
p.get(i - 1).setProId(p.get(i - 1).getProId() - 1);
}
flag = true;
}
}
if (flag) {
System.out.println("删除成功!");
count--;
} else {
try {
throw new TeamException("该项目不存在!");
} catch (TeamException e) {
e.printStackTrace();
}
}
}
//修改项目状态
public void updateStates(int proId){
Project project = p.get(proId);
project.setStatus(false);
p.set(proId,project);
}
public ArrayList<Project> getP() {
return p;
}
}
TeamService
package com.guanqia12.service;
import com.guanqia12.domain.Architect;
import com.guanqia12.domain.Designer;
import com.guanqia12.domain.Employee;
import com.guanqia12.domain.Programmer;
public class TeamService {
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;
int numOfDsgn = 0;
int 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;
}
}
TeamException
package com.guanqia12.service;
public class TeamException extends Exception {
public TeamException() {
}
public TeamException(String message) {
super(message);//打印异常信息
}
}