先看一下该项目的功能结构:
1.软件启动时,首先进入登录界面进行注册和登录功能。
2.当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。
3.然后可以对开发人员进行增删改操作
4.人员添加成功后,根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目。
5.组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。
6.团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。
![](https://img-blog.csdnimg.cn/img_convert/8ec30b3c11ad4aff2ac97b07477abb0a.png)
主要涉及以下知识点:
1.类的继承性和多态性
2.对象的值传递、接口
3.static和final修饰符
4.特殊类的使用:包装类、抽象类、内部类
5.异常处理
6.Java基本语法和流程控制
7.数组,ArrayList集合
该软件由以下三个模块组成:
![](https://img-blog.csdnimg.cn/img_convert/0e7e099aeeae8f57ecb243b2c79a0ed4.png)
com.team.view 模块为主控模块,负责菜单的显示和处理用户操作
com.team.service 模块为实体对象(Employee及其子类如程序员等)的管理模块, NameListService和TeamService类分别用各自的数组来管理公司员工和开发团队成员对象
ProjectService是对项目的操作对象类
domain模块为Employee及其子类等JavaBean类所在的包
主要代码演示
IndexView
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() throws TeamException, InterruptedException {
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':
//开发团队调度管理模块,这个用封装调用这个方法,下面会显示方法在哪
manyTeam = teamVi.getManyTeam(nameListSer);
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':
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) throws TeamException, InterruptedException {
new IndexView().menu();
}
}
TeamView模块
public class TeamView {
private TeamService ts = new TeamService();
private NameListService n = new NameListService();
private ArrayList<Programmer[]> team = new ArrayList<>();
//主界面
public void MainMenu(){
boolean b = true;
//显示输入列表
do {
listEmployees();
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出");
System.out.println("请选择(1-4)");
char c = TSUtility.readMenuSelection();
switch (c) {
case '1':
listTeam();
break;
case '2':
listEmployees();
addMember();
break;
case '3':
//listTeam();
DeleteMember();
break;
case '4':
System.out.println("请确认是否退出(Y/N)");
char c1 = TSUtility.readConfirmSelection();
if (c1 == 'Y') {
team.add(ts.getTeam());
ts.clearTeam();
b = false;
}
break;
default:
break;
}
}while (b);
}
public ArrayList<Programmer[]> getTeam(){
return team;
}
public void listEmployees(){
System.out.println("-----------------开发调度开发软件-------------------");
//获取所有员工数据
ArrayList<Employee> allEmployees = n.getAllEmployees();
if (allEmployees.size() == 0) {
System.out.println("无员工信息");
}else {
System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
for (int i = 0; i < allEmployees.size(); i++) {
System.out.println(" " + allEmployees.get(i));
}
}
System.out.println("------------------------------------------------");
}
//getManyTeam这个方法在前面case '2'中调用
public ArrayList<Programmer[]> getManyTeam(NameListService x)throws InterruptedException{
n=x;
boolean flag = true;
char key = 0;
do{//死循环
System.out.println("##########################");
System.out.println("##### #####");
System.out.println("##### 团队调度界面 #####");
System.out.println("##### #####");
System.out.println("##########################");
System.out.print("1-添加团队 2-查看团队 3-删除团队 4-退出 请选择(1-4):");
key = TSUtility.readMenuSelection();
System.out.println("---------------------------------------------");
switch (key){
case '1':
MainMenu();
break;
case '2':
System.out.println("----------团队列表---------");
try {
if (team.size() == 0) {
throw new InterruptedException();
} else {
System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
for (Programmer[] team : team) {
for (int i = 0; i < team.length; i++) {
System.out.println(team[i]);
}
System.out.println("======================================================================");
}
}
} catch (InterruptedException i) {
System.out.println("当前没有任何团队,请重新添加团队!" + i.getMessage());
}
break;
case '3':
System.out.println("请输入要删除第几个团队");
int num = TSUtility.readInt();
if (num<=team.size())
{
System.out.print("确认是否删除(Y/N):");
char de = TSUtility.readConfirmSelection();
if (de == 'Y') {
team.remove(num-1);
}else
{
System.out.println("请考虑清楚!");
}
}else {
System.out.println("没有该团队,请正常输入!"+"目前团队只有"+team.size()+"个");
}
break;
case '4':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
flag = false;
}
break;
default:
break;
}
}while (flag);
return team;
}
public void listTeam(){
System.out.println("-----------------团队成员列表-------------------");
Programmer[] team = ts.getTeam();
try {
if (team.length == 0) {
System.out.println("无开发团队成员");
} else {
System.out.println("TeamId/Id\t\t姓名\t\t年龄\t工资\t职位\t奖金\t股票");
for (int i = 0; i < team.length; i++) {
System.out.println(" " + team[i].getDetailsForTeam());
}
}
System.out.println("------------------------------------------------");
}catch (Exception e){
System.out.println("开发团队目前没有成员");
System.out.println("------------------------------------------------");
}
}
//添加成员
public void addMember(){
System.out.println("请输入要添加的队员ID");
int ID=TSUtility.readInt();
try{
Employee e = n.getEmployee(ID);
ts.addMember(e);
System.out.println("添加成功");
}catch (Exception | TeamException e){
System.out.println("添加失败"+e.getMessage());
}
TSUtility.readReturn();
}
//删除成员
public void DeleteMember(){
System.out.println("---------------------删除成员---------------------");
System.out.print("请输入要删除员工的TID:");
int id = TSUtility.readInt();
System.out.print("确认是否删除(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'N')
return;
try {
ts.removeMember(id);
System.out.println("删除成功");
} catch (TeamException e) {
System.out.println("删除失败,原因:" + e.getMessage());
}
// 按回车键继续...
TSUtility.readReturn();
}
}
loginView模块
package com.project1.src.com.team.view;
import java.util.Random;
import java.util.Scanner;
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) {
System.out.println("未检测到您的账号,请您先注册!");
regist();
}
//已注册
//正常登录
else if (this.userName.equals(userName) && this.password.equals(password)) {
TSUtility.loadSpecialEffects();
System.out.println("登陆成功!欢迎您:" + userName);
flag = false;
} else {
if (count <= 0) {
System.out.println("登录次数不足!退出!");
return;
} else {
count--;
System.out.println("登录失败!用户名或密码不匹配!");
System.out.println("登录次数还剩" + count + "次,请重新输入:");
}
}
}
}
//修改功能
public void update() throws InterruptedException {
boolean flag = true;
while (flag) {
System.out.println("********************🐱");
System.out.println("*** <修改界面> ***");
System.out.println("*** (: ***🐱");
System.out.println("********************🐱");
System.out.println("请输入你需要修改的类型:");
System.out.println("1(修改用户名)");
System.out.println("2(修改密码名)");
System.out.println("3(修改用户名和密码名)");
System.out.println("4(不修改,退出)");
Scanner sc = new Scanner(System.in);
String options = sc.next();
if (options.equals("1")) {
System.out.println("请输入你的修改的账户名称:");
String userName = TSUtility.readKeyBoard(4, false);
this.userName = userName;
System.out.println("修改成功!");
} else if (options.equals("2")) {
System.out.println("请输入你的修改密码:");
String 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”:");
}
}
}
}
TSUtility模块,用于输入
package com.project1.src.com.team.view;
import java.util.Random;
import java.util.Scanner;
public class TSUtility {
private static Scanner scanner = new Scanner(System.in);
public static char readMenuSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
public static char readMenuSelectionPro() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4' && c != '5') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static int readstock() {
int n;
for (; ; ) {
String str = readKeyBoard(6, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static Double readDouble() {
Double n;
for (; ; ) {
String str = readKeyBoard(6, false);
try {
n = Double.parseDouble(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static char readConfirmSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false).toUpperCase();
c = str.charAt(0);
if (c == 'Y' || c == 'N') {
break;
} else {
System.out.print("选择错误,请重新输入:");
}
}
return c;
}
public static String readString(int limit, String defaultValue) {
String str = readKeyBoard(limit, true);
return str.equals("")? defaultValue : str;
}
public static String readKeyBoard(int limit, boolean blankReturn) {
String line = "";
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if (line.length() == 0) {
if (blankReturn) return line;
else continue;
}
if (line.length() < 1 || line.length() > limit) {
System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
continue;
}
break;
}
return line;
}
public static void loadSpecialEffects() throws InterruptedException {
System.out.println("请稍等:");
for (int i1 = 1; i1 <= 100; i1++) {
System.out.print("加载中:" + i1 + "%");
Thread.sleep(new Random().nextInt(25) + 1);
if (i1 == 100) {
Thread.sleep(50);
}
System.out.print("\r");
}
}
}