实践项目1
項目開發團隊分配管理軟件
一、需求說明?
?1.1、用戶注冊和登錄模塊
- 定義一個LoginView類
- 實現注冊方法
- 如果沒有賬戶則需要注冊
- 如果有賬號則直接進行登錄
- 實現登錄功能
- 判斷用戶輸入的值是否正確
- 如果正確則進入軟件菜單 如果錯誤則重新輸入,限制次數只有5次,超過次數則程序停止,重新啟動
- 實現修改用戶密碼功能
- 可以實現對用戶名,密碼,或者兩者都可以進行修改即可。
?2、開發人員管理模塊
- Architect架構師實體類
- ?Designer 設計師實體類
-
Employee 人員類
- package com.team.domain;public class Employee {private int id;private String name;private int age;private double salary;public Employee() {}public Employee(int id, String name, int age, double salary) {this.id = id;this.name = name;this.age = age;this.salary = salary;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public double getSalary() {return salary;}public void setSalary(double salary) {this.salary = salary;}public String ObjectProperties() {return id + "\t" + name + "\t" + age + "\t\t" + salary;}@Overridepublic String toString() {return ObjectProperties();} }
- ????????實現員工的添加(根據職業添加(無,程序員,設計師,架構師))
- 實現員工的查看 (顯示所有數據)
- 實現員工的刪除(注意員工id需要動態顯示,也就是刪除后,員工id需要更新)
- 實現員工的修改(至少修改員工的姓名,年齡,工資)
?3、開發團隊調度管理模塊
package com.team.view;import com.team.domain.Employee; import com.team.domain.Programmer; import com.team.domain.Project; import com.team.service.NameListService; import com.team.service.ProjectService; import com.team.service.TeamException; import com.team.service.TeamService;import java.util.ArrayList;public class TeamView {private NameListService ListSvc = new NameListService();private TeamService teamSvc = new TeamService();ArrayList<Programmer[]> team = new ArrayList<>();//進入界面public void enterMainMenu() throws TeamException {boolean loopFlag = true;char key = 0;do {if (key != '1') {listAllEmlpoyees();}System.out.println("1-團隊列表 2-添加團隊成員 3-刪除團隊成員 4-退出");System.out.print("請選擇(1-4)");key = TSUtility.readMenuSelection();System.out.println();switch (key) {case '1':ListTeam();break;case '2':addMember();break;case '3':deleteMember();break;case '4':System.out.println("請確認是否要退出(Y/N)");char ch = TSUtility.readConfirmSelection();if (ch == 'Y') {team.add(teamSvc.getTeam());teamSvc.clearTeam();loopFlag = false;}break;default:System.out.println("輸入信息有誤,請重新輸入");break;}} while (loopFlag);}//顯示所有員工成員private void listAllEmlpoyees() {System.out.println("\n-----------------------開發團隊調度軟件----------------------------\n");ArrayList<Employee> emps = ListSvc.getAllEmployees();if (emps.size() == 0) {System.out.println("無客戶記錄。");} else {System.out.println("ID\t\t\t姓名\t\t年齡\t\t工資\t\t職位\t\t狀態\t\t獎金\t\t股票\t\t領用設備");}for (Employee e : emps) {//增強for循環System.out.println(" " + e);}System.out.println("--------------------------------------------------------------------");}//顯示開發團隊成員列表private void ListTeam() {System.out.println("--------------團隊成員列表------------");Programmer[] team = teamSvc.getTeam();if (team.length == 0) {System.out.println("開發團隊目前沒有成員");} else {System.out.println("TID\t\t姓名\t\t年齡\t工資\t職位\t獎金\t股票");}//增強for循環System.out.println("---------------------------------");for (Programmer p : team) {System.out.println(" " + p.toString());}System.out.println("----------------------------------");}//添加成員到團隊private void addMember() throws TeamException {System.out.println("-------------添加團隊成員-------------------");System.out.println("請輸入要添加的成員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();}//從團隊中刪除指定位置的成員private void deleteMember() {System.out.println("--------------刪除成員-------------");System.out.println("請入要刪除的員工TID");int TID = TSUtility.readInt();if (TID < 1) {try {throw new TeamException("不存在該員工的TID");} catch (TeamException e) {System.out.println(e.getMessage());}}System.out.println("請確認是否刪除(Y/N)");char yn = TSUtility.readConfirmSelection();if (yn == 'N') {return;}try {teamSvc.removeMember(TID);System.out.println("刪除成功");} catch (TeamException e) {System.out.println("刪除失敗,原因是" + e.getMessage());}TSUtility.readReturn();}//加入并得到更多的團隊public ArrayList<Programmer[]> getManyteam() throws TeamException {boolean flag = true;char key = 0;do {System.out.println("***************************");System.out.println("** **");System.out.println("** 團隊調度界面 **");System.out.println("** **");System.out.println("***************************");System.out.println("1-添加團隊 2-查看團隊 3-刪除團隊 4-退出");System.out.print("請選擇(1-4)");key = TSUtility.readMenuSelection();switch (key) {case '1':enterMainMenu();break;case '2'://加強for循環該怎么用System.out.println("-----團隊列表-----");for (Programmer[] team : team) {for (int i = 0; i < team.length; i++) {System.out.println(team[i]);}System.out.println("------------");teamSvc.clearTeam();}if (team.size() == 0) {System.out.println("當前無團隊,請先添加團隊");}break;case '3':if (team.size() == 0) {try {throw new TeamException("當前無團隊,請先添加團隊");} catch (TeamException e) {System.out.println(e.getMessage());}}if (team.size() != 0) {System.out.println("請輸入要刪除第幾個團隊");int num = TSUtility.readstock();if (num <= team.size()) {System.out.print("請確認是否刪除(Y/N)");char de = TSUtility.readConfirmSelection();if (de == 'Y') {//釋放團隊Programmer[] programmer =team.get(num-1);for (int i = 0; i <team.get(num-1).length ; i++) {programmer[i].setStatus(true);}team.remove(num-1);//釋放團隊名稱Project project = ProjectService.getPro().get(num-1);project.setTeam(new Programmer[0]);project.setTeamName(null);project.setStatus(false);ProjectService.getPro().set(num-1,project);} else {System.out.println("請考慮清楚");}} else {System.out.println("沒有該團隊,請正常輸入!" + "目前團隊只有" + team.size() + "個");}}break;case '4':System.out.println("是否退出(Y/N)");char yn = TSUtility.readConfirmSelection();if (yn == 'Y') { // team.add(teamSvc.getTeam());flag = false;}break;default:System.out.println("輸入信息有誤,請重新輸入");break;}} while (flag);return team;} }4、開發項目管理模塊
package com.team.domain;public class Project {// 項目號 proId int-private int proID;// 項目名稱 projectName Stringprivate String projectName;//- 項目描述 desName Stringprivate String desName;//- 開發團隊 team Programmer[]-private Programmer[] team = new Programmer[10];//開發團隊名稱 teamName String-private String teamName;// 開發狀態 status false(true為開發中,false為未開發中))private boolean status = false;public Project() {}public Project(int proID, String projectName, String desName, Programmer[] team, String teamName, boolean status) {this.proID = proID;this.projectName = projectName;this.desName = desName;this.team = team;this.teamName = teamName;this.status = status;}public int getProID() {return proID;}public void setProID(int proID) {this.proID = proID;}public String getProjectName() {return projectName;}public void setProjectName(String projectName) {this.projectName = projectName;}public String getDesName() {return desName;}public void setDesName(String desName) {this.desName = desName;}public Programmer[] getTeam() {return team;}public void setTeam(Programmer[] team) {this.team = team;}public String getTeamName() {return teamName;}public void setTeamName(String teamName) {this.teamName = teamName;}public boolean isStatus() {return status;}public void setStatus(boolean status) {this.status = status;}@Overridepublic String toString() {return proID + "\t" + "項目名稱:" + projectName + "\t 內容為:" + desName + "\t團隊名稱" + teamName + "開發狀態是:" + status;} }5、IndexView類的設計
package com.team.view; import com.team.domain.Programmer; import com.team.service.NameListService; import com.team.service.ProjectService; import com.team.service.TeamException;import java.util.ArrayList;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 ProjectService getProjectSer() {return projectSer;}public void setProjectSer(ProjectService projectSer) {this.projectSer = projectSer;}public void menu() throws InterruptedException, TeamException {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("🐕");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("🔣 🔣");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.revise();} 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.changeEmployee(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;}default:System.out.println("輸入有誤!請重新輸入!");break;}} while (loopFlagSec);break;case '3':try{manyTeam=teamVi.getManyteam();}catch (Exception e){e.printStackTrace();}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':try {if (manyTeam==null){System.out.println("沒有團隊,請先添加團隊");}else {if (projectSer.getPro().size()==0){System.out.println("有"+manyTeam.size()+"個團隊,沒項目,請先添加項目");} else if (projectSer.getPro().size()<manyTeam.size()) {System.out.println("請再去添加"+(manyTeam.size()-projectSer.getPro().size())+"個項目任務");} else {for (Programmer[] pro : manyTeam) {projectSer.dealingPro(pro);}}}}catch (NullPointerException e){e.printStackTrace();}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) throws InterruptedException, TeamException {new IndexView().menu();} }其他代碼已打包放入百度網盤里
鏈接:https://pan.baidu.com/s/1k1JlMkF733uZOWHGWFRINw?
提取碼:2202
總結
在刪除隊伍團隊的時候需要釋放團隊里的團隊成員,并且也需要釋放相對應的團隊名稱的信息。在運行的時候將可能出現的問題即使應用try,catch來進行把任務接收進行對其的更改。對于隨機分配項目的時候需要考慮有重復的分配,導致不能將全部的任務進行分配。
總結
- 上一篇: 如何给孩子的作文下评语
- 下一篇: lua的GC原理