模拟实现一个基于文本界面的《项目开发团队分配管理软件》
该软件由以下三个模块组成:
在domain包中完成各个类的实体类创建
com.team.domain模块中包含了所有实体类:
其中程序员(Programmer)及其子类,均会领用某种电子设备(Equipment)
继承关系
其中属性前面得符号涉及到UML类图,这里我们使用到了下列符号
更多关于类图的知识可以额外扩展搜索,这里就不多做赘述了
在NameListService类中完成功能操作
在domain包中完成项目实体类Project的创建
在service包中完成项目操作类ProjectService的创建
public class TSUtility {
private static Scanner scanner=new Scanner(System.in);
//输入值限定长度
public static String readKeyBoard(int i, boolean b) {
String line="";
//当输入的时候进入判断
while (scanner.hasNextLine()){
line=scanner.nextLine();
if (line.length()==0){
if (b)
return line;
else
continue;
}
if (line.length()<1 || line.length()>i){
System.out.println("输入长度(不大于" + i + ")错误,请重新输入:");
continue;
}
break;
}
return line;
}
//提示回车键继续
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
//菜单五个限选方法
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 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 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");
}
}
//输入double类型的数
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;
}
//输入int类型的数
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 String readString(int i, String defaultValue) {
String str = readKeyBoard(i, true);
return str.equals("")? defaultValue : str;
}
//退出系统
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 char readMenuSelectionMini() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' ) {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
}
//注册
public void regist(){
System.out.println("********************🐱");
System.out.println("*** <注册界面> ***");
System.out.println("*** :) ***🐱");
System.out.println("********************🐱");
//如果没有账户则需要注册
System.out.println("开始注册:");
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 {
//登陆失败次数限制5次
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(ANSI_RESET + ANSI_GREEN);
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.不修改,退出");
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-4:");
}
}
}
/**
* 管理公司员工
*
* 实现员工的添加(根据职业添加(无,程序员,设计师,架构师))
* 实现员工的修改(至少修改员工的姓名,年龄,工资)
* 实现员工的删除(注意员工id需要动态显示,也就是删除后,员工id需要更新)
* 实现员工的查看 (显示所有数据)
*
*/
public class NameListService {
//用来装员工的数据集合
private ArrayList<Employee> 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 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;
}
//获取指定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 showEmployee() throws InterruptedException {
TSUtility.loadSpecialEffects();
System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
for (int i = 0; i < employees.size(); i++) {
System.out.println(" " + employees.get(i));
}
}
//增加员工
public void addEmployee() {
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 modifyEmployee(int id) {
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();
}
}
}
//删除员工
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 class TeamService {
//用来为开发团队新增成员自动生成团队中的唯一ID
private static int counter = 1;
//表示开发团队最大成员数
private final int MAX_MEMBER = 5;
//保存当前团队中的各成员对象集合
private Programmer[] team = new Programmer[MAX_MEMBER];
//记录团队成员的实际人数
private int total = 0;
public TeamService(){}
/**
* getTeam()方法:返回当前团队的所有对象
* 返回:包含所有成员对象的数组,数组大小与成员人数一致
* @return
*/
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;
}
/**
* addMember(e: Employee)方法:向团队中添加成员
* 参数:待添加成员的对象
* 异常:添加失败, TeamException中包含了失败原因
* @param
* @throws TeamException
*/
public void addMember(Employee e){
if (total >= MAX_MEMBER) {
throw new TeamException("添加失败,成员已满,无法添加");
} else if (!(e instanceof Programmer)) {
throw new TeamException("添加失败,该成员不是开发人员,无法添加");
}
Programmer p=(Programmer)e;
if (isExist(p)) {
throw new TeamException("添加失败,该员工已在本开发团队中");
}
if (!p.getStatus()) {
throw new TeamException("添加失败,该员工已是某团队成员");
}
int numOfA = 0;
int numOfD = 0;
int numOfP = 0;
for (int i = 0; i < total; i++) {
if (team[i] instanceof Architect) {
numOfA++;
} else if (team[i] instanceof Designer) {
numOfD++;
} else {
numOfP++;
}
}
if (p instanceof Architect) {
if (numOfA >= 1)
{throw new TeamException("团队中至多只能有一名架构师");}
} else if (p instanceof Designer) {
if (numOfD >= 2)
{throw new TeamException("团队中至多只能有两名设计师");}
} else if (p instanceof Programmer) {
if (numOfP >= 3)
{throw new TeamException("团队中至多只能有三名程序员");}
}
p.setStatus(false);
p.setMemberId(counter++);
team[total++] = p;
}
public boolean isExist(Programmer p){
for (int i = 0; i < total; i++) {
//如果输入的能在集合里找到一样的id就确认为存在
if (team[i].getId()==p.getId()){
return true;
}
}
return false;
}
/**
* removeMember(memberId: int)方法:从团队中删除成员
* 参数:待删除成员的memberId
* 异常:找不到指定memberId的员工,删除失败
* @param memberId
* @throws TeamException
*/
public void removeMember(int memberId){
int n=0;
for (;n<total;n++){
if (team[n].getMemberId() == memberId) {
team[n].setStatus(true);
/*for (int i = 0; i < total; i++) { //团队内id递补
int memberId1 = team[i].getMemberId();
if (memberId1 > memberId) {
team[i].setMemberId(memberId1 - 1);
}
}*/
break;
}
}
//如果找不到就报异常
if (n==total){
throw new TeamException("找不到该成员,无法删除");
}
//后面的元素覆盖前面的元素
for (int i = n + 1; i < total; i++) {
team[i - 1] = team[i];
}
team[--total] = null;
}
}
public class TeamView {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_CYAN = "\u001B[36m";
private NameListService listSvc = new NameListService();
private TeamService teamSvc = new TeamService();
private ArrayList<Programmer[]> team = new ArrayList<>();
public TeamView(){}
public void enterMainMenu (){
boolean loopFlagT = true;
char keyS = 0;
do {
System.out.println("------------------------开发团队调度软件-------------------------");
try {
this.listAllEmployees();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("---------------------------------------------------------------");
System.out.print(ANSI_RESET + ANSI_CYAN);
System.out.print("1-查看团队成员 ");
System.out.print("2-添加团队成员 ");
System.out.print("3-删除团队成员 ");
System.out.print("4-退出 ");
System.out.print("请选择(1-4): ");
keyS=TSUtility.readMenuSelection();
switch (keyS){
//1-查看团队成员
case '1':
getTeam();
break;
//2-添加团队成员
case '2':
addMember();
break;
//3-删除团队成员
case '3':
deleteMember();
break;
//4-退出
case '4':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
if (teamSvc.getTeam().length==0){
loopFlagT = false;
}else {
team.add(teamSvc.getTeam());
//删除数据
teamSvc.clearTeam();
loopFlagT=false;
}
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
} while (loopFlagT);
}
//以表格形式列出公司所有成员
// 以表格形式列出公司所有成员
private void listAllEmployees() throws InterruptedException {
listSvc.showEmployee();
}
//显示团队成员列表操作
private void getTeam() {
System.out.println("-------------团队成员列表-------------");
Programmer[] team =teamSvc.getTeam();
//无团队
if (team.length==0){
System.out.println("当前没有团队信息,请先添加团队!");
return;
}else {
System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
}
//for循环遍历
for (Programmer teamNum : team) {
System.out.println(teamNum.getMemberId()+"/"+teamNum);
}
TSUtility.readReturn();
}
//实现添加成员操作
private void addMember(){
System.out.println("-------------------------添加成员------------------------");
System.out.println("请输入要添加的员工ID:");
int id=TSUtility.readInt();
try {
Employee addEmployee = listSvc.getEmployee(id);
teamSvc.addMember(addEmployee);
System.out.println("添加成功");
} catch (TeamException e) {
System.out.println(e.getMessage());
}
TSUtility.readReturn();
}
//实现删除成员操作
private void deleteMember() {
Programmer[] team = teamSvc.getTeam();
if (team.length==0){
System.out.println("暂无团队成员,请先添加");
return;
}
System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
for (Programmer teamNum : team) {
System.out.println(teamNum.getMemberId()+"/"+teamNum);
}
System.out.println("-------------------------删除成员------------------------");
System.out.println("请输入需要删除的团队成员ID:");
int id = TSUtility.readInt();
System.out.print("确认是否删除(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'N'){
return;
}
try {
teamSvc.removeMember(id);
System.out.println("删除成功");
} catch (Exception e) {
System.out.println(e.getMessage());
}
TSUtility.readReturn();
}
public ArrayList<Programmer[]> getManyTeam() {
boolean loopFlagTea = true;
char keyTea = 0;
//listSvc=nameListSer;//传入对象赋值
do {
System.out.print(ANSI_RESET + ANSI_BLUE);
System.out.println("※※※※※※※※※※※※");
System.out.println("※ 团队调度界面 ※");
System.out.println("※※※※※※※※※※※※");
System.out.print("1-添加团队 ");
System.out.print("2-查看团队 ");
System.out.print("3-删除团队 ");
System.out.print("4-编辑团队 ");
System.out.print("5-退出 ");
System.out.print("请选择(1-5): ");
keyTea=TSUtility.readMenuSelectionPro();
switch (keyTea){
//1-添加团队
case '1':
enterMainMenu();
break;
//2-查看团队
case '2':
teamList();
break;
//3-删除团队
case '3':
teamDelete();
break;
//4-编辑团队
case '4':
teamEdit();
break;
//4-退出
case '5':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagTea = false;
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
} while (loopFlagTea);
return team;
}
private void teamEdit() {
System.out.println("-------------团队列表-------------");
if (team.size()==0){
System.out.println("暂无团队,请先添加团队");
}else {
System.out.println("请输入想要编辑第几个团队");
int id = TSUtility.readInt();
boolean loop=true;
char key=0;
if (id<=team.size()){
for (Programmer[] team : team) {
for (int i = 0; i < team.length; i++) {
if (id == team[i].getMemberId()){
do {
System.out.println("------------------------开发团队调度软件-------------------------");
try {
this.listAllEmployees();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("---------------------------------------------------------------");
System.out.print(ANSI_RESET + ANSI_CYAN);
System.out.print("1-添加团队成员 ");
System.out.print("2-删除团队成员 ");
System.out.print("3-查看团队成员 ");
System.out.print("4-退出 ");
System.out.print("请选择(1-4): ");
key=TSUtility.readMenuSelection();
switch (key){
//1-添加团队成员
case '1':
addMember();
break;
//2-删除团队成员
case '2':
deleteMember();
break;
//3-查看团队成员
case '3':
getTeam();
break;
//4-退出
case '4':
System.out.print("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
if (teamSvc.getTeam().length==0){
loop = false;
}else {
teamSvc.clearTeam();
loop=false;
}
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
}while (loop);
}
}
}
}else {
System.out.println("没有该团队,请正常输入!" + "目前团队只有" + team.size() + "个");
}
}
TSUtility.readReturn();
}
private void teamDelete() {
System.out.println("-------------团队列表-------------");
if (team.size()==0){
System.out.println("暂无团队,请先添加团队");
}
System.out.println("请输入想要删除第几个团队");
int num = TSUtility.readInt();
if (num <= team.size()) {
System.out.print("确认是否删除(Y/N):");
char d = TSUtility.readConfirmSelection();
if (d == 'Y') {
team.remove(num - 1);
System.out.println("删除成功");
//更新开发团队状态
if (ProjectService.pro.size()!=0){
for (int i = 0; i < ProjectService.pro.size(); i++) {
ProjectService.pro.get(i).setTeamName(null);
ProjectService.pro.get(i).setTeam(null);
ProjectService.pro.get(i).setStatus(false);
}
}
} else {
System.out.println("请确认!");
}
} else {
System.out.println("没有该团队,请正常输入!" + "目前团队只有" + team.size() + "个");
}
TSUtility.readReturn();
}
private void teamList() {
System.out.println("-------------团队列表-------------");
if (team.size() == 0) {
System.out.println("暂无团队,请先添加团队");
} else {
System.out.println("ID\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("-------------------------------------");//分割开团队
}
}
TSUtility.readReturn();
}
}
注意:这个项目的编辑团队功能目前还未完善,但其余功能不影响使用
/**
* 对项目的操作对象类
*
* 项目参考:
* 1.小米官网:开发完成类似于小米官网的web项目
* 2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城,以商城B2C模式运营的公益在线商城。
* 3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!使用了轻量级 mvc 框架Blade开发,默认主题使用了漂亮的pinghsu。
* 4.在线协作文档编辑系统:多人在线协作文档编辑器是一个很常用的功能,适合小组内的文档编辑。
*/
public class ProjectService {
//用来存项目的集合
public static ArrayList<Project> pro = new ArrayList<>();
//添加项目的标号
private int count = 1;
private TeamService teamService=new TeamService();
public ProjectService() {
}
//新项目添加
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.setProjectName("小米官网");
p1.setDesName("开发完成类似于小米官网的web项目.");
pro.add(p1);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p1.getProjectName());
break;
case '2':
Project p2 = new Project();
p2.setProId(count++);
p2.setProjectName("公益在线商城");
p2.setDesName("猫宁Morning公益商城是中国公益性在线电子商城.");
pro.add(p2);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p2.getProjectName());
break;
case '3':
Project p3 = new Project();
p3.setProId(count++);
p3.setProjectName("博客系统");
p3.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
pro.add(p3);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p3.getProjectName());
break;
case '4':
Project p4 = new Project();
p4.setProId(count++);
p4.setProjectName("在线协作文档编辑系统");
p4.setDesName("一个很常用的功能,适合小组内的文档编辑。");
pro.add(p4);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p4.getProjectName());
break;
default:
System.out.println("项目不存在");
break;
}
}
//项目分配团队开发
public void dealingPro(Programmer[] team) {
for (Project proj : pro) {
boolean status=proj.isStatus();
/*if (teamService.getTeamTotal()<=count()){
System.out.println("没有空余团队");
}else */
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 ra = new Random();
int ranNum = ra.nextInt(pro.size());
Project project = this.pro.get(ranNum);
if (!project.isStatus()){
project.setTeamName(teamName);
project.setTeam(team);
project.setStatus(true);//删除团队成功后这三个属性之后置空
pro.set(ranNum,project);
System.out.println("项目分配成功");
}
return;
}
System.out.println("当前没有待开发项目");
}
}
private int count() {
int count=0;
for (Project proj : pro) {
if (proj.getProjectName()!=null){
count++;
}
}
return count;
}
//查看项目当前状态
public void showPro() throws InterruptedException {
TSUtility.loadSpecialEffects();
try {
if (pro.size()==0){
throw new TeamException("当前没有项目,请先添加");
}else {
for (int i = 0; i < pro.size(); i++) {
if (pro.get(i).isStatus()==false){
System.out.println(pro.get(i));
System.out.println("项目【"+pro.get(i).getProjectName()+"】---->未被开发!");
}else if (pro.get(i).isStatus()==true){
System.out.println("项目【"+pro.get(i).getProjectName()+"】---->正在被团队【"+pro.get(i).getTeamName()+"】开发中!");
}
}
}
} catch (TeamException e) {
System.out.println(e.getMessage());
}
}
//删除选择的项目
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.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 {
System.out.println("当前项目正在被开发,无法删除!");
}
}else {
try {
throw new TeamException("该项目不存在,当前只有"+pro.size()+"个项目");
} catch (TeamException e) {
System.out.println(e.getMessage());
}
}
}
}
}
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(){
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();
}
boolean loopFlag = true;
char key = 0;
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){
//1. <用户信息修改>
case '1':
try {
loginVi.update();
//修改完了之后重新登录
System.out.println("是否重新登录?(Y/N)");
char c = TSUtility.readConfirmSelection();
//重新登录
if (c == 'Y'){
loginVi.login();
}else {//不重新登陆就退出
loopFlag = false;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
//2. <开发人员管理>
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) {
//1. <开发人员的添加>
case '1':
nameListSer.addEmployee();
break;
//2. <开发人员的查看>
case '2':
try {
nameListSer.showEmployee();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
//3. <开发人员的修改>
case '3':
System.out.println("请输入需要修改的员工id:");
int i = TSUtility.readInt();
nameListSer.modifyEmployee(i);
break;
//4. <开发人员的删除>
case '4':
System.out.println("请输入需要删除的员工id:");
int j = TSUtility.readInt();
nameListSer.delEmployee(j);
break;
//5. <退出当前菜单>
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;
//3. <开发团队调度管理>
case '3':
manyTeam = teamVi.getManyTeam();
break;
//4. <开发项目管理>
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){
try {
throw new TeamException("当前没有团队,请先添加团队");
} catch (TeamException e) {
System.out.println(e.getMessage());
}
}else {
for (Programmer[] pro : manyTeam) {
projectSer.dealingPro(pro);
}
}
break;
//项目的查看
case '3':
try {
projectSer.showPro();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
//项目的删除
case '4':
if (ProjectService.pro.size()==0){
try {
throw new TeamException("当前没有项目,请先添加");
} catch (TeamException e) {
System.out.println(e.getMessage());
}
}else {
System.out.println("请输入需要删除的项目id:");
int id = TSUtility.readInt();
projectSer.delPro(id);
}
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;
//5. <退出软件>
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();
}
}