提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
项目开发团队是一个适合java入门的一个小系统,它可以检验你后端的学习状况到底如何,知识点掌握的是否牢靠。
提示:以下是本篇文章正文内容,下面案例可供参考
一、整体架构
整个系统分为三个模块,分别为domain,service,view模块,domain、模块中装着本系统所需的实体类和接口。service模块中装着具体要实现功能的逻辑,view模块包含着整个系统的前端
二、关键代码
1.projectservice代码
代码如下(示例):
public class ProjectService {
private ArrayList<Project> 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("------------------------------------------------------------");
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项目.");
pro.add(p1);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p1.getProName());
break;
case '2':
Project p2 = new Project();
p2.setProId(count++);
p2.setProName("公益在线商城");
p2.setDesName("猫宁Morning公益商城是中国公益性在线电子商城.");
pro.add(p2);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p2.getProName());
break;
case '3':
Project p3 = new Project();
p3.setProId(count++);
p3.setProName("博客系统");
p3.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
pro.add(p3);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p3.getProName());
break;
case '4':
Project p4 = new Project();
p4.setProId(count++);
p4.setProName("在线协作文档编辑系统");
p4.setDesName("一个很常用的功能,适合小组内的文档编辑。");
pro.add(p4);
TSUtility.loadSpecialEffects();
System.out.println("已添加项目:"+p4.getProName());
break;
default:
System.out.println("项目不存在");
break;
}
}
//给项目分配团队
public void dealingPro(Programmer[] team) {
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);
//随机分配项目
if(team.length!=0){//判断team是否为空
Random ra = new Random();
int ranNum = ra.nextInt(pro.size());
Project project = this.pro.get(ranNum);
if (project.isStatus()==false) {
project.setTeamName(teamName);
project.setTeam(team);
project.setStatus(true);
pro.set(ranNum, project);
System.out.println("项目分配成功");
}else {
System.out.println("项目分配失败");
}
}
}
//查看目前项目情况
public void showPro() throws InterruptedException {
if (pro.size()==0) {
TSUtility.loadSpecialEffects();
System.out.println("请先添加项目");
}
for (int i = 0; i < pro.size(); i++) {
System.out.println(pro.get(i));
}
}
//删除选择的项目
public void delPro(int id){
boolean flag = false;
for (int i = 0; i < pro.size(); i++) {
if (pro.get(i).getProId() == id) {
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 {
try {
throw new TeamException("该项目不存在");
} catch (TeamException e) {
e.printStackTrace();
}
}
}
//得到所有项目数据集合
public ArrayList<Project> getAllPro() {
return pro;
}
}
2.teamview
代码如下(示例):
public class TeamView {
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 (Exception e) {
e.printStackTrace();
}
System.out.println("1.查看团队成员");
System.out.println("2.添加团队成员");
System.out.println("3.删除团队成员");
System.out.println("4.退出");
keyS = TSUtility.readMenuSelection();
switch (keyS) {
case '1':
//查看团队成员
getTeam();
break;
case '2':
//添加团队人员
addMember();
break;
case '3':
//删除团队成员
deleteMember();
break;
case '4':
//退出
System.out.println("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagT = false;
team.add(teamSvc.getTeam());
teamSvc.clearTeam();
}
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 (Programmer teamNum : team) {
System.out.println(teamNum.getMemberId()+"/"+teamNum);
}
}
TSUtility.readReturn();
}
/*
* 添加成员
* */
private void addMember() {
System.out.println("请输入添加成员的id");
int id = TSUtility.readInt();
try {
Employee addEmployee = listSvc.getEmployee(id);
teamSvc.addMember(addEmployee);
System.out.println("添加成功");
} catch (TeamException e) {
e.printStackTrace();
}
TSUtility.readReturn();
}
/*
* 删除成员
* */
private void deleteMember() {
Programmer[] team = teamSvc.getTeam();
if (team.length == 0) {
System.out.println("该团队为空,请添加团队");
return;
}
System.out.println("请输入要删除的成员id");
System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
for (Programmer teamNum : team) {
System.out.println(teamNum.getMemberId()+"/"+teamNum);
}
int id = TSUtility.readInt();
try {
teamSvc.removeMember(id);
System.out.println("删除成功");
} catch (TeamException e) {
e.printStackTrace();
}
TSUtility.readReturn();
}
/*
* 开发人员管理
* */
public ArrayList<Programmer[]> getManyTeam() {
boolean loopFlagTea = true;
char keyTea = 0;
while(loopFlagTea){
System.out.println("<开发人员管理>");
System.out.println("1.添加团队");
System.out.println("2.查看团队");
System.out.println("3.删除团队");
System.out.println("4.退出");
keyTea = TSUtility.readMenuSelectionPro();
switch (keyTea){
case'1':
/*
* 添加团队*/
enterMainMenu();
break;
case'2':
/*
* 查看团队*/
teamList();
break;
case'3':
/*
* 删除团队*/
teamDelete();
break;
case'4':
System.out.println("确认是否退出(Y/N):");
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagTea = false;
}
break;
default:
System.out.println("输入有误!请重新输入!");
break;
}
}
return team;
}
private void teamDelete() {
if(team.size() == 0){
System.out.println("暂无团队,请添加");
}
System.out.println("请输入您要删除的团队");
int num = TSUtility.readInt();
if(num<=team.size()){
team.remove(num-1);
System.out.println("删除成功");
}else{
System.out.println("重新输入");
}
TSUtility.readReturn();
}
private void teamList() {
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();
}
}
总结
以上为本人修改项目开发团队分配系统的关键代码