项目名称:项目开发团队分配管理软件
功能结构:
1)用户注册和登录。实现用户注册信息,用户登录功能,用户修改功能。
2)开发人员管理。实现开发人员的添加、修改、查询、删除。
3)开发团队调度管理。查看团队列表,添加团队成员,删除团队成员。
4)开发项目管理。实现新项目的添加,随机分配开发团队,项目开发情况查看,项目的删除。
5)退出系统。
需求说明:
1)软件启动时,首先进入登陆界面进行注册和登陆功能。
2)登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。
3)然后可以对开发人员进行增删改操作。
4)人员添加成功后,根据现有的公司成圆,组建一个开发团队以开发一个新的项目。
5)组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。
6)团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。
先根据系统功能结构图,将整个软件大概分为四个模块,逐步实现每个模块,最后将四个模块进行整合,测试输出。
1.需要对用户输入的账户和密码进行判断,是否在限定范围内
Scanner中关于next()、nextLine()、hasNext()、hasNextLine()的区别
分析:
1)
上图源自https://blog.csdn.net/qq_45722053/article/details/120087631
解决:
1)
//读取键盘输入长度
public static String readKeyboard(int limit, boolean blankReturn){
String line = "";
while(sc.hasNextLine()){
line = sc.nextLine();
if(line.length() == 0){
if(blankReturn) return line;
else continue;
}
if(line.length()<0 || line.length()>limit){
System.out.println("输入的长度请不小于"+limit+",请重新输入:");
continue;
}
break;
}
return line;
}
图来自https://ask.csdn.net/questions/7528641
2.测试的时候,没有检测到是否存在账号的用户名和密码。
分析:
1)发现是局部变量隐藏了成员变量
解决:
1)使用关键字this
//未注册
if(this.userName.length() == 0 || this.password.length() == 0){
System.out.println("没有检测到您的账号信息,请您先注册");
TSUtility.loadSpecialEffects();
register();
}
1.如何修改输入指定ID的员工信息
分析:
1)遍历找到与指定的ID相符的员工信息索引,删除后,将后一个元素的id减一。
解决:
1)
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 t) {
t.printStackTrace();
}
}
}
}
1.在单独添加团队成员时,删除对应的成员,展示成员列表没有显示TID,并且职位没有变化。
System.out.println(p.get(i));
分析:
1)
若只是p.get(i),输出的是该索引指向的元素信息,并不是。
所以需要在Programmer类中定义在加入团队后的雇员信息,也就是团队ID(TID)加上,雇员信息。
解决:
1)
首先在TeamView类中的添加成员的方法设置每次添加成功后的成员团队id,用counter++,先设置couter值本身,操作完毕后自增一。
p.setMemberId(counter++);
然后在Programmer中定义getMemberDetails()方法,返回添加成员后的团员id信息和雇员信息;
再定义一个getDetailsForTeam() 方法之后在Designer和Architect中重写这个方法,并修改相应的职位信息。
protected String getMemberDetails() {
return getMemberId() + "/" + getDetails();
}
public String getDetailsForTeam() {
return getMemberDetails() + "\t程序员";
}
2)
然后是在TeamView中定义showTeam() 方法,满足判断条件后,输出p.get(i).getDetailsForTeam()得到的信息。
public void showTeam() throws TeamException {
System.out.println("\n--------------------团队成员列表---------------------\n");
ArrayList p = teamSvc.getTeam();
if(p.size() == 0){
System.out.println("目前没有开发团队!");
}else {
System.out.println("TID/ID" + " \t 姓名" + "\t\t年龄" + "\t\t工资" + "\t\t职位");
for(int i = 0; i < p.size(); i++){
System.out.println(p.get(i).getDetailsForTeam());
}
}
System.out.println("---------------------------------------------------");
}
2.如何打印输出多个团队的成员信息。
分析:
1)首先先确定团队格式,第一层for循环实现i个团队,第二层for循环实现j个成员的信息输出。
解决:
1)
case "2"://查看团队
if(team1.size() == 0) {
System.out.println("当前没有团队,请先添加");
}else{
System.out.println("-------团队列表--------");
//表头
for (int i = 0; i < team1.size(); i++) {
//表头
System.out.println("第" + (i + 1) + "个团队:");
System.out.println("TID/ID" + " \t 姓名" + "\t\t年龄" + "\t\t工资" + "\t\t职位");
for (int j = 0; j < team1.get(i).size(); j++) {
System.out.println(team1.get(i).get(j).getDetailsForTeam());
}
System.out.println("------------------");
}
}
break;
3.如何保证删除团队时,不索引越界。
分析:
1)首先先确定团队格式,第一层for循环实现先实现是在开发人员范围内,第二层for循环实现i个团队,注意删除这个团队,意味这该团队成员的状态也要随之改变,所以第三层for循环实现当前团队中j个成员,找到这个成员在集合中的位置并修改状态。
小于等于0时,团队号不存在,超出团队号范围,输出提示信息。
解决:
1)
case "3"://删除团队
System.out.println("请输入想要删除第几个团队:");
int num = sc4.nextInt();
if(num <= 0) {
try{
throw new TeamException("团队号输入不正确,请重新输入!");
}catch(TeamException t){
System.out.println(t.getMessage());
}
} else if (num <= team1.size()) {
//删除整个团队时,状态应该随之修改,防止索引越界
ArrayList t = nls.getAllEmployees();
for (int n = 0; n < t.size(); n++) {
for (int i = num; i <= team1.size(); i++) {
for (int j = 0; j < team1.get(i-1).size(); j++) {
//team1.get(num -1)之所以为num-1,是因为集合中这个元素不能改变
if(team1.get(num-1).get(j).getId() == t.get(n).getId()) {
//转换集合对象的类型,设置状态。
Programmer employee = (Programmer)t.get(n);
employee.setStatus(true);
}
}
}
}
team1.remove(num - 1);
System.out.println("删除成功");
} else {
System.out.println("团队中没有这个团队,请正常输入,目前只有" + team1.size() + "个团队");
}
break;
1.项目如何随机分配开发团队
分析:
1)在团队和项目的个数一致时,用for(::)循环实现对多个团队进行团队分配。定义方法使用随机数分配
解决:
1)先定义项目分配团队的方法,输出当前团队人员并命名,先用随机数获取项目,设置项目的团队名团队名称和状态,最后将对象放进集合中
2)在项目随机分配开发团队中,先判断是否有无项目,有项目之后再利用for循环,对多个项目进行分配,所以是
for (ArrayList pro : manyTeam) {
projectService.dealingPro(pro);
}
3.如何指定分配项目给相应的团队。例如团队1开发项目2,团队2开发项目1。
分析:
1)先判断是否有项目和团队的存在,再用for( : : )循环调用多次指定分配方法;
2)定义指定调用方法,先设置当前队伍的名字,显示项目列表,输入项目号为当前队伍分配,没有找到相应的项目显示分配失败,重新输入。
解决:
1)
//指定分配
if(projectService.getAllPro().size() == 0){
System.out.println("当前没有项目,请先添加!");
}else if (manyTeam == null){
System.out.println("当前没有团队,请先添加!");
} else{
for (ArrayList pro : manyTeam) {
projectService.specifyPro(pro);
}
}
public void specifyPro(ArrayList team) throws InterruptedException {
{//显示团队信息
System.out.println("当前团队有人员:");
System.out.println("编号" + "\t\t姓名" + " \t\t年龄" + "\t\t工资" + "\t\t职位" + "\t\t状态" + "\t\t奖金" + "\t\t股票" + "\t\t\t设备");
for (int j = 0; j < team.size(); j++) {
System.out.println(team.get(j));
}
}
//设置名称
System.out.println("请为当前团队给定一个名称:");
String teamName = TSUtility.readKeyBoard(6, false);
boolean flag = true;
while(flag){
//显示所有添加后的项目
/*System.out.println("-------------------------------项目列表-------------------------------");
System.out.println(pro);
System.out.println("---------------------------------------------------------------------");*/
showPro();
System.out.println("1. 分配项目");
System.out.println("2. 返回");
System.out.println("请选择:");
char ch = TSUtility.readMenuSelection();
switch (ch) {
case '1':
//为当前团队指定项目
System.out.println("请为当前团队指定开发项目,输入项目号:");
int nId = TSUtility.readInt();
//遍历
for(int i = 0; i < pro.size(); i++){
if( pro.get(i).getProId() == nId ){
Project p = this.pro.get(i);
//修改状态
p.setTeamName(teamName);
p.setStatus(true);
p.setTeam(team);
//将对象放入项目集合当中
pro.set(i, p);
System.out.println("项目:" + pro.get(i) + "分配给团队:" + teamName);
flag = false;
}
}
if( flag == true ){
System.out.println("分配失败,请重新输入!");
}
break;
case '2':
flag =false;
break;
}
}
}
public class LoginView {
private String userName = "";
private String password = "";
//注册
public void register(){
System.out.println("----开始注册----");
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的注册账户名称:");
String userName = TSUtility.readKeyBoard(5,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("请输入你的登录账户名称:");
String userName = TSUtility.readKeyBoard(5, false);
System.out.println("请输入你的登录账户密码:");
String password = TSUtility.readKeyBoard(8, false);
//未注册
if(this.userName.length() == 0 || this.password.length() == 0){
System.out.println("没有检测到您的账号信息,请您先注册");
TSUtility.loadSpecialEffects();
register();
}
//已注册
//成功注册
else if(this.userName.equals(userName) && this.password.equals(password)){
System.out.println("登录成功!欢迎"+userName);
flag= false;
}
//输入不对
else{
if(count<0){
System.out.println("登录次数不够!退出!");
}
else{
count--;
System.out.println("账户名称和密码不匹配!");
System.out.println("登录次数还余"+count+"次,请重新输入:");
}
}
}
}
//修改用户、密码
public void update(){
boolean flag = true;
while(flag){
//修改界面
System.out.println("********************************");
System.out.println("*** <修改界面> ***");
System.out.println("********************************");
Scanner sc = new Scanner(System.in);
System.out.println("1(修改用户名)");
System.out.println("2(修改密码)");
System.out.println("3(修改用户名和密码)");
System.out.println("4(退出)");
System.out.println("请输入你想要进行的操作:");
String option = sc.next();
//1修改用户名
if(option.equals("1")){
System.out.println("请输入你要修改的用户名:");
String userName = TSUtility.readKeyBoard(5,false);
this.userName = userName;
System.out.println("修改成功!");
}
//2修改密码
else if(option.equals("2")){
System.out.println("请输入你要修改的密码:");
String password = TSUtility.readKeyBoard(8,false);
this.password = password;
System.out.println("修改成功!");
}
//3修改用户名和密码
else if(option.equals("3")){
System.out.println("请输入你要修改的用户名:");
String userName = TSUtility.readKeyBoard(5,false);
this.userName = userName;
System.out.println("请输入你要修改的密码:");
String password = TSUtility.readKeyBoard(8,false);
this.password = password;
System.out.println("修改成功!");
}
//4退出
else if(option.equals("4")){
System.out.println("退出成功!");
flag = false;
}
//输入不规范
else{
System.out.println("输入错误!请输入1/2/3/4/:");
}
}
}
}
public class NameListService {
public ArrayList 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 Architect(++count, "雷军 ", 50, 10000, new Printer("激光", "佳能2900"), 5000, 2000));
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 getAllEmployees() {
return employees;
}
//获取指定ID的员工对象
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 pr = new Programmer(++count, name, age, salary, pc);
employees.add(pr);
System.out.println("人员添加成功!");
TSUtility.readReturn();
}//Designer(++count,"史玉柱",27,7800,new NoteBook("惠普m6",5800),1500)
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 n = new NoteBook().addNotebook();
System.out.println("请输入当前雇员的奖金:");
double bonus = TSUtility.readDouble();
Designer d = new Designer(++count, name, age, salary, n, bonus);
employees.add(d);
System.out.println("人员添加成功!");
TSUtility.readReturn();
}
//Architect(++count, "杨元庆", 35, 6500, new Printer("针式", "爱普生20k"), 15500, 1200)
else if (c.equals("4")) {
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 pr = new Printer().addPrinter();
System.out.println("请输入当前雇员的奖金:");
double bonus = TSUtility.readDouble();
System.out.println("请输入当前雇员的股票:");
int stock = TSUtility.readInt();
Architect a = new Architect(++count, name, age, salary, pr, bonus, stock);
employees.add(a);
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("删除成功!");
}
}
}
if(flag == false){
System.out.println("找不到该员工!");
}
}
//员工的查看
public void showEmployee () throws InterruptedException {
TSUtility.loadSpecialEffects();
System.out.println("ID\t\t姓名\t\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) {
boolean flag = false;
for (int i = 0; i < employees.size(); i++) {
Employee emp = employees.get(i);
if (emp.getId() == id) {//找到员工id
//得到修改后的信息
System.out.println("姓名(" + emp.getName() + "):");
String name = TSUtility.readString(4, emp.getName());
System.out.println("年龄(" + emp.getAge() + "):");
int age = Integer.parseInt(TSUtility.readString(2, emp.getName()));
System.out.println("工资(" + emp.getSalary() + "):");
double salary = Double.parseDouble(TSUtility.readString(2, emp.getName()));
//修改后的信息进行设置
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 t) {
t.printStackTrace();
}
}
}
}
}
public class TeamService {
//定义team编号,从1开始
int counter = 1;
//定义集合最大值,即我们团队最多只能放入多少个成员
final int MAX_MEMBER = 5;
ArrayList team = new ArrayList();
//团队的实际人数
int total = 0;
//创建新对象放数据
public void clearTeam() {
this.team=new ArrayList();
total = 0;
counter = 1;
}
//查看所有团队
public ArrayList getTeam() throws TeamException {
for (int i = 0; i < team.size(); i++) {
team.set(i, this.team.get(i));
}
return team;
}
//增加团队成员
public void addMember(Employee e) throws TeamException {
//判断成员是否满5个
if (total >= MAX_MEMBER) {
throw new TeamException("成员已满,无法添加");
}
//判断添加的成员是否为开发人员,即他是否是我们程序员类的实例对象
if (!(e instanceof Programmer)) {
throw new TeamException("该成员不是开发人员,无法添加");
}
//向下转型,利用父类引用转为子类对象,调用子类特有方法
Programmer p = (Programmer) e;
//如果我们的集合当中已经有了这个成员,抛出异常。
if (team.contains(p)) {
throw new TeamException("该员工已在本团队中");
}
//如果这个成员被另一个团队录取,
if (!p.isStatus()) {
throw new TeamException("该员工已是某团队成员");
}
//定义工程师,架构师,和程序员的数量,初始化为0;
int numOfArch = 0, numOfDesi = 0, numOfPrg = 0;
for (int i = 0; i < total; i++) {
if (team.get(i) instanceof Architect) {
numOfArch++;
} else if (team.get(i) instanceof Designer) {
numOfDesi++;
} else if (team.get(i) instanceof Programmer) {
numOfPrg++;
}
}
//判断如果我们的成员类型超过了规定的数量,则程序抛出异常
if (p instanceof Architect) {
if (numOfArch >= 1) {
throw new TeamException("团队中至多只能有一名架构师");
}
} else if (p instanceof Designer) {
if (numOfDesi >= 2) {
throw new TeamException("团队中至多只能有两名设计师");
}
} else if (p instanceof Programmer) {
if (numOfPrg >= 3) {
throw new TeamException("团队中至多只能有三名程序员");
}
}
//修改状态
p.setStatus(false);
//改团队ID
p.setMemberId(counter++);
//放入我们的对象进集合
team.add(total++, p);
}
//删除指定memberId的程序员
public void removeMember(int MemberId) throws TeamException {
int n = 0;
boolean flag = false;
for (; n < total; n++) {
if (team.get(n).getMemberId() == MemberId) {
team.get(n).setStatus(true);
team.remove(n);
for (n = MemberId; n < total; n++) {
//将第i个对象从集合中删除之后,前一个对象的ID就应该相应的减一。
team.get(n - 1).setMemberId(team.get(n - 1).getMemberId() - 1);
}
flag = true;
break;
}
}
if (flag) {
System.out.println("成员删除成功!");
total--;
counter--;
} else {
try{
throw new TeamException("删除失败,该员工不存在");
}catch(TeamException t) {
System.out.println("原因:" + t.getMessage());
}
}
}
//便于获得新的团队集合
public ArrayList getTeamX() {
return team;
}
}
public class TeamView {
NameListService listSvc = new NameListService();
TeamService teamSvc = new TeamService();
//主界面显示及控制方法
public void enterMainMenu(NameListService listSvc) throws InterruptedException, TeamException {
boolean flag = true;
while (flag) {
System.out.println("-------------------------开发团队调度软件-------------------------");
listAllEmployees(listSvc);
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4):");
Scanner sc = new Scanner(System.in);
String option2 = sc.next();
switch (option2) {
case "1":
showTeam();
break;
case "2":
addMember(listSvc);
break;
case "3":
deleteMember();
break;
case "4":
ArrayList teamX = teamSvc.getTeamX();
if (teamX.size() == 0) {
teamSvc.clearTeam();
} else {
team1.add(teamX);
teamSvc.clearTeam();
}
flag = false;
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
//表格形式列出公司所有成员
public void listAllEmployees(NameListService listSvc) throws InterruptedException {
ArrayList emp = listSvc.getAllEmployees();
if (emp.size() == 0) {
System.out.println("没有团队成员记录!");
} else {
System.out.println("编号" + "\t\t姓名" + "\t\t\t年龄" + "\t\t工资" + "\t\t职位" + "\t\t状态" + "\t\t奖金" + "\t\t股票" + "\t\t\t领用设备");
for (int i = 0; i < emp.size(); i++) {
System.out.println(emp.get(i));
}
}
System.out.println("---------------------------------------------------");
}
//显示团队成员列表操作
public void showTeam() throws TeamException {
System.out.println("\n--------------------团队成员列表---------------------\n");
ArrayList p = teamSvc.getTeam();
if (p.size() == 0) {
System.out.println("目前没有开发团队!");
} else {
System.out.println("TID/ID" + " \t 姓名" + "\t\t年龄" + "\t\t工资" + "\t\t职位");
for (int i = 0; i < p.size(); i++) {
System.out.println(p.get(i).getDetailsForTeam());
}
}
System.out.println("---------------------------------------------------");
}
//实现添加成员操作
public void addMember(NameListService listSvc) {
System.out.println("------------------添加成员------------------");
System.out.println("请输入要添加的员工ID:");
Scanner sc = new Scanner(System.in);
int id = sc.nextInt();
try {
Employee e = listSvc.getEmployee(id);
teamSvc.addMember(e);
System.out.println("添加成功!");
}catch(TeamException t){
System.out.println("添加失败,原因"+t.getMessage());
}
}
//实现删除成员操作
public void deleteMember() throws TeamException {
System.out.println("------------------删除成员------------------");
System.out.println("当前团队有成员:");
showTeam();
System.out.println("请输入你要删除的员工的团队TID:");
Scanner sc = new Scanner(System.in);
int id = sc.nextInt();
if(listSvc.employees.size() >= id){
teamSvc.removeMember(id);
} else {
System.out.println("输入员工不存在,请重新输入!");
}
}
//团队调度界面
ArrayList> team1 = new ArrayList<>();
public ArrayList> getManyTeam(NameListService nls) throws TeamException, InterruptedException {
boolean flag = true;
while (flag) {
System.out.println("=============================");
System.out.println("|---------团队调度界面---------|");
System.out.println("=============================");
System.out.println("1-添加团队 2-查看团队 3-删除团队 4-退出 请选择(1-4):");
Scanner sc4 = new Scanner(System.in);
String choice = sc4.next();
switch (choice) {
case "1":
//进入添加团队方法
enterMainMenu(nls);
break;
case "2"://查看团队
if(team1.size() == 0) {
System.out.println("当前没有团队,请先添加");
}else{
System.out.println("-------团队列表--------");
//表头
for (int i = 0; i < team1.size(); i++) {
//表头
System.out.println("第" + (i + 1) + "个团队:");
System.out.println("TID/ID" + " \t 姓名" + "\t\t年龄" + "\t\t工资" + "\t\t职位");
for (int j = 0; j < team1.get(i).size(); j++) {
System.out.println(team1.get(i).get(j).getDetailsForTeam());
}
System.out.println("------------------");
}
}
break;
case "3"://删除团队
System.out.println("请输入想要删除第几个团队:");
int num = sc4.nextInt();
if(num <= 0) {
try{
throw new TeamException("团队号输入不正确,请重新输入!");
}catch(TeamException t){
System.out.println(t.getMessage());
}
} else if (num <= team1.size()) {
//删除整个团队时,状态应该随之修改,防止索引越界
ArrayList t = nls.getAllEmployees();
for (int n = 0; n < t.size(); n++) {//开发人员12个
for (int i = num; i <= team1.size(); i++) {//团队个数
for (int j = 0; j < team1.get(i-1).size(); j++) {//当前团队人数
//team1.get(num -1)之所以为num-1,是因为集合中这个元素不能改变
if(team1.get(num-1).get(j).getId() == t.get(n).getId()) {
//转换集合对象的类型,设置状态。
Programmer employee = (Programmer)t.get(n);
employee.setStatus(true);
}
}
}
}
team1.remove(num - 1);
System.out.println("删除成功");
} else {
System.out.println("团队中没有这个团队,请正常输入,目前只有" + team1.size() + "个团队");
}
break;
case "4":
flag = false;
break;
default:
break;
}
}
return team1;
}
}
public class Project extends Programmer {
private int proId;//项目号
private String proName;//项目名称
private String desName;//项目描述
private ArrayList team;//开发团队
private String teamName;//开发团队名称
private boolean status = false;//开发状态
//构造
public Project(){};
public Project(int proId, String proName, String desName,
ArrayList team, String teamName, boolean status){
this.proId = proId;
this.proName = proName;
this.desName = desName;
this.team = team;
this.teamName = teamName;
this.status = status;
}
//设置获取
public ArrayList getTeam() {
return team;
}
public void setTeam(ArrayList team) {
this.team = team;
}
public int getProId() {
return proId;
}
public void setProId(int proId) {
this.proId = proId;
}
public String getProName() {
return proName;
}
public void setProName(String proName) {
this.proName = proName;
}
public String getDesName() {
return desName;
}
public void setDesName(String desName) {
this.desName = desName;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public void setStatus(boolean status) {
this.status = status;
}
@Override
public boolean isStatus() {
return status;
}
@Override
public String toString() {
return "项目{项目号=‘"+proId+"’ 项目名=‘"+proName+"’,项目描述=‘"+desName
+"’,开发团队名称=‘"+teamName+"’,开发状态="+status+"}";
}
}
public class ProjectService {
int first = -1;
int second = -1;
int third = -1;
int forth = -1;
//
private ArrayList 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("------------------------------------------------------------");
System.out.println("请输入你想添加的项目号: ");
Scanner sc2=new Scanner(System.in);
String c=sc2.next();
switch (c) {
case "1":
Project p1 = new Project();
p1.setProName("小米官网");
p1.setDesName("开发完成类似于小米官网的web项目.");
if (first == -1) {
//防止count在重复添加时依然自增,导致编号出问题
p1.setProId(count++);
pro.add(p1);
System.out.println("项目:" + p1.getProName() + "添加成功!");
first++;
} else {
System.out.println("项目:" + p1.getProName() + "已添加,请勿重复添加!");
}
break;
case "2":
Project p2 = new Project();
p2.setProName("公益在线商城");
p2.setDesName("猫宁Morning公益商城是中国公益性在线电子商城.");
if (second == -1) {
p2.setProId(count++);
pro.add(p2);
//加载语句
System.out.println("项目:" + p2.getProName()+ "添加成功!");
second++;
} else {
System.out.println("项目:" + p2.getProName() + "已添加,请勿重复添加!");
}
break;
case "3":
Project p3 = new Project();
p3.setProName("博客系统");
p3.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
if (third == -1) {
p3.setProId(count++);
pro.add(p3);
//加载语句
System.out.println("项目:" + p3.getProName() + "添加成功!");
third++;
} else {
System.out.println("项目:" + p3.getProName() + "已添加,请勿重复添加!");
}
break;
case "4":
Project p4 = new Project();
p4.setProName("在线协作文档编辑系统");
p4.setDesName("一个很常用的功能,适合小组内的文档编辑。");
if (forth == -1) {
p4.setProId(count++);
pro.add(p4);
//加载语句
forth++;
System.out.println("项目:" + p4.getProName() + "添加成功!");
} else {
System.out.println("项目:" + p4.getProName() + "已添加,请勿重复添加!");
}
break;
default:
System.out.println("项目不存在!");
break;
}
}
//项目随机分配团队
public void dealingPro(ArrayList team) throws TeamException {
System.out.println("当前团队有人员:");
System.out.println("编号" + "\t\t姓名" + " \t\t年龄" + "\t\t工资" + "\t\t职位" + "\t\t状态" + "\t\t奖金" + "\t\t股票" + "\t\t\t设备");
for (int j = 0; j < team.size(); j++) {
System.out.println(team.get(j));
}
System.out.println("请为当前团队给定一个名称:");
String teamName=TSUtility.readKeyBoard(6, false);
//用随机数获取项目,随机分配
Random r = new Random();
int rNum = r.nextInt(pro.size());
Project project = this.pro.get(rNum);
//设置开发项目团队名
project.setTeamName(teamName);
//设置开发项目的团队
project.setTeam(team);
//设置开发状态,true为开发中
project.setStatus(true);
//将对象放入项目集合当中
pro.set(rNum, project);
System.out.println("项目:" + pro.get(rNum) + "分配给团队:" + teamName);
}
//指定团队开发项目
public void specifyPro(ArrayList team) throws InterruptedException {
{//显示团队信息
System.out.println("当前团队有人员:");
System.out.println("编号" + "\t\t姓名" + " \t\t年龄" + "\t\t工资" + "\t\t职位" + "\t\t状态" + "\t\t奖金" + "\t\t股票" + "\t\t\t设备");
for (int j = 0; j < team.size(); j++) {
System.out.println(team.get(j));
}
}
//设置名称
System.out.println("请为当前团队给定一个名称:");
String teamName = TSUtility.readKeyBoard(6, false);
boolean flag = true;
while(flag){
//显示所有添加后的项目
/*System.out.println("-------------------------------项目列表-------------------------------");
System.out.println(pro);
System.out.println("---------------------------------------------------------------------");*/
showPro();
System.out.println("1. 分配项目");
System.out.println("2. 返回");
System.out.println("请选择:");
char ch = TSUtility.readMenuSelection();
switch (ch) {
case '1':
//为当前团队指定项目
System.out.println("请为当前团队指定开发项目,输入项目号:");
int nId = TSUtility.readInt();
//遍历
for(int i = 0; i < pro.size(); i++){
if( pro.get(i).getProId() == nId ){
Project p = this.pro.get(i);
//修改状态
p.setTeamName(teamName);
p.setStatus(true);
p.setTeam(team);
//将对象放入项目集合当中
pro.set(i, p);
System.out.println("项目:" + pro.get(i) + "分配给团队:" + teamName);
flag = false;
}
}
if( flag == true ){
System.out.println("分配失败,请重新输入!");
}
break;
case '2':
flag =false;
break;
}
}
}
//项目查看
public void showPro() throws InterruptedException {
//加载语句
if (pro.size() == 0) {
System.out.println("当前没有项目,请先添加");
} else {
for (int i = 0; i < pro.size(); i++) {
// System.out.println(pro.get(i));
if(pro.get(i).getTeamName() == null){
System.out.println("项目号【"+pro.get(i).getProId()+"】,项目名【"+pro.get(i).getProName()+"" +
"】————>没有团队开发!");
}else{
System.out.println("项目号【"+pro.get(i).getProId()+"】,项目名【"+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 ) {
if(pro.get(i).isStatus() == false) {
pro.get(i).setStatus(true);
//不要忘了我们的自增变量要减
if(pro.get(i).getProName().equals("小米官网")) {
first = -1;
}else if(pro.get(i).getProName().equals("公益在线商城")){
second = -1;
}else if(pro.get(i).getProName().equals("博客系统")) {
third = -1;
}else if(pro.get(i).getProName().equals("在线协作文档编辑系统")) {
forth = -1;
}
pro.remove(i);
//集合中第i个元素的前一位I-1位元素的ID应该减一
for (i = id; i < pro.size(); i++) {
pro.get(i - 1).setProId(pro.get(i - 1).getProId() - 1);
}
flag = true;
}else if(pro.get(i).isStatus() == true) {
try{
throw new TeamException(pro.get(i) + "项目正在被开发,不能删除");
}catch(TeamException t) {
System.out.println("删除失败,原因:" + t.getMessage());
}
return;
}
}
}
if (flag) {
System.out.println("项目删除成功");
count--;
} else {
try {
throw new TeamException("项目不存在,删除失败");
} catch (TeamException t) {
System.out.println("删除失败,原因:" + t.getMessage());
}
}
}
//返回所有的项目
public ArrayList getAllPro() {
return pro;
}
}
public class IndexView {
private LoginView loginView = new LoginView();
private TeamView teamView = new TeamView();
private NameListService nameListService = new NameListService();
private ProjectService projectService = new ProjectService();
private ArrayList> manyTeam=null;
public void menu() throws TeamException, InterruptedException {
boolean loopFlag = true;
char key = 0;
System.out.println("————————————————————————————————————————");
System.out.println();
System.out.println(" 欢迎来到项目开发团队分配管理软件 ");
System.out.println();
System.out.println("————————————————————————————————————————");
System.out.println();
System.out.println("—————————————<请您先进行登录>————————————— ");
TSUtility.readReturn();
try{
loginView.login();
}catch (InterruptedException i){
i.printStackTrace();
}
do{
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("*请选择: *");
key = TSUtility.readMenuSelectionPro();
switch (key) {
case '1'://信息更改
loginView.update();
break;
case '2'://开发人员管理
try{
nameListService.showEmployee();
} catch (InterruptedException e){
e.printStackTrace();
}
boolean loopFlagSec = true;
char keySec = 0;
do{
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{
nameListService.addEmployee();
} catch (InterruptedException i){
i.printStackTrace();
}
break;
case '2':
try{
nameListService.showEmployee();
} catch (InterruptedException i){
i.printStackTrace();
}
break;
case '3':
System.out.println("请输入需要修改的员工id:");
int i = TSUtility.readInt();
nameListService.modifyEmployee(i);
break;
case '4':
System.out.println("请输入需要删除的员工id:");
int j = TSUtility.readInt();
nameListService.delEmployee(j);
break;
case '5':
System.out.println("确认是否退出(Y/N):");
char t = TSUtility.readConfirmSelection();
if (t == 'Y') {
loopFlagSec = false;
}
break;
default:
System.out.println("输入错误!请重新输入:");
break;
}
}while (loopFlagSec);
break;
case '3'://开发团队调度
manyTeam = teamView.getManyTeam(nameListService);
break;
case '4'://开发项目管理
boolean loopFlagThr = true;
char keyThr = 0;
do {
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("*请选择: ");
keyThr=TSUtility.readMenuSelectionPro();
switch (keyThr) {
case '1':
try {
projectService.addProject();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case '2'://项目分配开发团队
/*//随机分配
if(projectService.getAllPro().size() == 0){
System.out.println("当前没有项目,请先添加!");
}else{
for (ArrayList pro : manyTeam) {
projectService.dealingPro(pro);
}
}*/
//指定分配
if(projectService.getAllPro().size() == 0){
System.out.println("当前没有项目,请先添加!");
}else if (manyTeam == null){
System.out.println("当前没有团队,请先添加!");
} else{
for (ArrayList pro : manyTeam) {
projectService.specifyPro(pro);
}
}
break;
case '3':
try {
projectService.showPro();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case '4':
System.out.println("请输入需要删除的项目id:");
int j = TSUtility.readInt();
projectService.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.println("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if(yn == 'Y'){
loopFlag = false;
}
break;
default:
break;
}
}while (loopFlag);
}
public static void main(String[] args) throws InterruptedException, TeamException {
new IndexView().menu();
}
}