项目开发团队分配管理软件
1. 项目需求:
•该软件实现以下功能:
1.软件启动时,首先进入登录界面进行注册和登录功能。
2.当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。
3.然后可以对开发人员进行增删改操作
4.人员添加成功后,根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目。
5.组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。
6.团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。
2. 项目的结构图(mvc):
3.部分效果展示:
4. 项目的整体思路:
4.1 实体类及数据存储
拿到需求的时候 ,项目中的开发成员是分为几个类别,普通员工、程序员、设计师和架构师。所以先要给这个几个开发成员创建好他们各自的类。他们共有的属性都是有名字、年龄、,然后对于非普通员工的成员是要为他们每个人分配设备的,设备又分为打印机、笔记本、电脑。所以我们又要定义三个设备的类。
然后对于能添加到开发团队的开发成员要想判断该成员是否能忙碌。如果忙碌的话说明不能添加到开发团队里。那么就可以定义一个枚举类,枚举类表示员工的状态,比如忙碌、空闲、休假等。接着就可以定义团队类了,团队类的属性就有开发人员的集合和团队的teamid。跟着来到项目类,项目类里面有这个项目的项目projectid名称,项目的描述,项目的开发团队,和项目的状态。
接着就是想的是存储数据的问题,怎么把数据存下来程序在运行的时候就能保持程序的存储不会丢失,一是用户的账号密码数据,然后是开发人员的数据以及开发团队的数据。首先我把开发人员的默认数据存入我Data类里面的集合,让程序一运行进入软件主页面的时候就把Data里面的默认的数据读入到程序内存放数据的集合内。然后就是用户的数据,我的想法就是定义一个用户类,属性为int类型的账号和密码。再Data里面设置几个默认的user对象的集合,程序运行的时候读取这个里面的默认对象的集合,就可以做到不用注册直接使用Data里面的默认账号密码来进行登录,但也可以直接注册, 再注册功能的实现里就会先判断我的存放Data 的集合内有没有相同的账号,如果有的话,则会注册失败,实现的账号的唯一性,再Data类里还有一个存放默认项目的类的集合。里面有几个默认的项目,程序运行是也会直接把这个默认的值读取到程序内部的项目集合里面。到此,数据的存储问题就解决了。
4.2 界面类
首先,我创建了一个用户登录的界面(LoginView),这个界面是进入主程序的唯一入口,验证用户成功,则才会进入主程序的主页面(MainView)。进入MainView后,会有对应的选项,每个选项里都还嵌套了一个界面,而这几个页面都将其封装为几个类。
4.3 服务类
有了实体类和界面的类,接下来就应该写对应的业务服务类。对于不同的界面页面分为不同的服务类,对于员工有一个类,对于团队有一个类,还有对于项目有一个类。还有一个工具类,用于获取对用户的各种输入。还有一个异常类。对某些获取异常进行抛出。
5.项目代码及部分解释:
5.1 代码结构图:
5.2 实体类代码:
5.2.1 Employee 类:
package com.team.domain;
public class Employee {
private int id ;//员工id
private String name ;//员工名字
private int age ;//年龄
private double salary;//薪水
String getTostring(){//获取id name age salary 因为员工的信息每一条都有这个但不仅仅是有这个 所以把他包装成方法
return id +" "+'\t'+ name +" "+'\t' + age+'\t' + salary+'\t' ;
}
//ID 姓名 年龄 工资 职位 状态 奖金 股票 领用设备
// 1 马云 22 3000.0
public String toString() {
return id +" "+'\t'+ name +" "+'\t' + age+'\t' + salary+'\t' ;
}
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;
}
}
5.2.2 Programmer 类:
package com.team.domain;
public class Programmer extends Employee {
private int memberId;//该员工在团队中的id
private Status status;//该员工的状态 Status为枚举类
private Equipment equip ;//该员工配备的设备 (电脑/打印机/笔记本)
private String position = "程序员";
public Programmer(int id, String name, int age, double salary, Status status, Equipment equip) {
super(id, name, age, salary);
this.status = status;
this.equip = equip;
}
//ID 姓名 年龄 工资 职位 状态 奖金 股票 领用设备
//1 马云 22 3000.0
//2 李彦宏 23 7000.0 程序员 BUSY 戴尔(NEC 17寸)
@Override
public String toString() {//开发人员管理的时候调用 子类也一样
return super.getTostring()+'\t'+ position+'\t'+getStatus()+'\t'+'\t'+'\t'+'\t'+'\t'+equip.getDiscription();
}
//TID/ID 姓名 年龄 工资 职位 奖金
//1/ 10 张朝阳 35 7100.0 程序员
//2/ 11 杨致远 38 9600.0 设计师 3000.0
//3/ 7 杨元庆 35 6500.0 架构师 15500.0
public String toStringForTeam(){//团队管理的时候调用。子类也一样
return getMemberId()+"/ "+getId()+'\t'+'\t'+getName()+'\t'+'\t'+getAge()+'\t'+'\t'+getSalary()+'\t'+'\t'+getPosition()+'\t'+'\t';
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public Equipment getEquip() {
return equip;
}
public void setEquip(Equipment equip) {
this.equip = equip;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
}
5.2.3 Designer 类:
package com.team.domain;
public class Designer extends Programmer {
private double bonus;//奖金,
private String designer="设计师";
public Designer(int id, String name, int age, double salary, Status status, Equipment equip, double bonus) {
super(id, name, age, salary, status, equip);
this.bonus = bonus;
}
public String getDesigner() {
return designer;
}
//5/12 杨致远 27 600.0 设计师 4800.0
@Override
public String toStringForTeam() {
return getMemberId()+"/ "+getId()+'\t'+'\t'+getName()+'\t'+'\t'+getAge()+'\t'+'\t'+getSalary()+'\t'+'\t'+getDesigner()+'\t'+'\t'+getBonus();
}
//ID 姓名 年龄 工资 职位 状态 奖金 股票 领用设备
// 1 马云 22 3000.0
//4 雷军 50 10000.0 设计师 FREE 5000.0 激光(佳能2900)
//7 杨元庆 35 6500.0 架构师 FREE 15500.0 1200 针式(爱普生20k)
@Override
public String toString() {
return super.getTostring()+'\t'+designer+'\t'+getStatus()+'\t'+bonus+'\t'+'\t'+'\t'+getEquip().getDiscription();
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
}
5.2.4 Architect 类:
package com.team.domain;
public class Architect extends Designer {
private int stock;//股嫖
private String architect ="架构师";
public Architect(int id, String name, int age, double salary, Status status, Equipment equip, double bonus, int stock) {
super(id, name, age, salary, status, equip, bonus);
this.stock = stock;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
//ID 姓名 年龄 工资 职位 状态 奖金 股票 领用设备
// 1 马云 22 3000.0
//4 雷军 50 10000.0 设计师 FREE 5000.0 激光(佳能2900)
//7 杨元庆 35 6500.0 架构师 FREE 15500.0 1200 针式(爱普生20k)
@Override
public String toString() {
return super.getTostring()+'\t'+architect+'\t'+getStatus()+'\t'+getBonus()+'\t'+stock+'\t'+getEquip().getDiscription();
}
@Override
public String toStringForTeam() {
return getMemberId()+"/ "+getId()+'\t'+'\t'+getName()+'\t'+'\t'+getAge()+'\t'+'\t'+getSalary()+'\t'+'\t'+getArchitect()+'\t'+'\t'+getBonus();
}
public String getArchitect() {
return architect;
}
}
5.2.5 设备类:printer 类
package com.team.domain;
public class Printer implements Equipment{
private String name ;
private String type;
@Override
public String getDiscription() {
return name+"("+type+")";
}
public Printer(String name, String type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
5.2.6 设备类:PC 类:
package com.team.domain;
public class PC implements Equipment {
private String model;
private String display;
public PC(String model, String display) {
this.model = model;
this.display = display;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
@Override
public String getDiscription() {
return model+"("+display+")";
}
}
5.2.6 设备类:
package com.team.domain;
public class NoteBook implements Equipment{
private String model;
private double price;
@Override
public String getDiscription() {
return model+"("+price+")";
}
public NoteBook(String model, double price) {
this.model = model;
this.price = price;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
5.2.7 设备接口类:Equipment 类
package com.team.domain;
public interface Equipment {
String getDiscription();
}
5.2.8 Team 类:
package com.team.domain;
import java.util.ArrayList;
public class Team {
private ArrayList<Programmer> program;// 用于存取团队的成员
private static int size;// 用于获取团队里面的成员数量。
private int teamid;
public Team (){
program = new ArrayList<>();
size = 0;
}
public Team(ArrayList<Programmer> program) {
this.program = program;
size++;
}
public int getTeamid() {
return teamid;
}
public void setTeamid(int teamid) {
this.teamid = teamid;
}
public static int getSize() {
return size;
}
public static void setSize(int size) {
Team.size = size;
}
@Override
public String toString() {
return "Team" + teamid;
}
public ArrayList<Programmer> getProgram() {
return program;
}
public void setProgram(ArrayList<Programmer> program) {
this.program = program;
}
}
5.2.9 Project 类:
package com.team.domain;
import java.util.ArrayList;
/**
* descripiton:开发项目的类
* */
public class Project {
private int projectID ;// 项目id
private String projectName; //项目名字
private String projectDescription;//项目的描述
private Team team; //做该项目的团队
private boolean STATUE;// 项目的状态
@Override
public String toString() {//项目添加的时候使用。
return "项目id:"+projectID+'\t'+"项目名称:"+projectName +'\t'+"项目描述:" + projectDescription +'\t'+'\t' +'\t'+" 项目团队=null" +'\t'+"开发状态:"+ isSTATUE();
}
public String toString1() {//项目分配 的时候使用
return "项目id:"+projectID+'\t'+"项目名称:"+projectName +'\t'+"项目描述:" + projectDescription +'\t'+'\t' +'\t'+" 项目团队= Team" + team.getTeamid()+'\t'+"开发状态:"+ isSTATUE();
}
public Project(int projectID, String projectName, String projectDescription, Team team, boolean STATUE) {
this.projectID = projectID;
this.projectName = projectName;
this.projectDescription = projectDescription;
this.team = team;
this.STATUE = STATUE;
}
public boolean isSTATUE() {
return STATUE;
}
public int getProjectID() {
return projectID;
}
public void setProjectID(int projectID) {
this.projectID = projectID;
}
public void setSTATUE(boolean STATUE) {
this.STATUE = STATUE;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getProjectDescription() {
return projectDescription;
}
public void setProjectDescription(String projectDescription) {
this.projectDescription = projectDescription;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}
}
5.2.10 枚举类: Status 类:
package com.team.domain;
public enum Status {
// public static final String free = "FREE";
// public static final String busy = "FREE";
FREE,BUSY,VCATION;//状态 空闲 忙碌 休假
}
5.2.11 User 类:
package com.team.domain;
import java.util.Objects;
/**
* description:用户的账号密码
* */
public class User {
private int acount;
private int password;
public User(){
}
public User(int acount, int password) {
this.acount = acount;
this.password = password;
}
public int getAcount() {
return acount;
}
public void setAcount(int acount) {
this.acount = acount;
}
public int getPassword() {
return password;
}
public void setPassword(int password) {
this.password = password;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return acount == user.acount ;
}
@Override
public int hashCode() {
return Objects.hash(acount, password);
}
}
5.3 工具类 Tools 类:
package com.team.service;
import java.util.Random;
import java.util.Scanner;
public class Tools {
private static Scanner scanner = new Scanner(System.in);
public static char readMenuSelectionUserView() {//用于获取菜单选项为3个选项的输入
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 static char readMenuSelection() {//用于获取菜单选项为4个选项的输入
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() {//用于获取菜单选项为5个选项的输入
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 readMenuSelectionProMax() {//用于获取菜单选项为6个选项的输入
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4' && c != '5' && c !='6') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
public static int readInt() {// 获取用户输入为2个字符的数字(用于获取各种id)
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的6个字符(用于获取工资)
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() { // 用于获取Y或者N 提醒用户是否要退出
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) { // 获取获取名字等,如果是defaultValue则不改变原来的值
String str = readKeyBoard(limit, true);
return str.equals("")? defaultValue : str;
}
public static int readModifyInt(int limit, String defaultValue) { //同上 获取修改的int,如果为defaultValue, 则不不修改原来的值
String str = readKeyBoard(limit, true);
return str.equals("")? Integer.parseInt(defaultValue) : Integer.parseInt(str);
}
public static double readModifyDouble(int limit, String defaultValue) {
String str = readKeyBoard(limit, true);
return str.equals("")? Double.parseDouble(defaultValue) : Double.parseDouble(str);
}
public static int readAountAndPassword() {// 获取账号密码。
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 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");
}
}
}
5.4 View 类
5.4.1 Login 类:
package com.team.view;
import com.team.domain.User;
import com.team.service.Data;
import com.team.service.Tools;
import java.util.ArrayList;
/**
* descripiton:用户登录界面
* */
public class LoginView {
public static int password; // 密码
public static int acount; //账户
public static User USER; // 当前登录的用户
public static ArrayList<User> USERS; // 全部用户的集合
private boolean flagLogin = true;
private boolean flag=true;
public LoginView() {
USERS = Data.USERS; //将Data内的默认用户传入到我真正的用户集合里面。
USER = new User();
init();
}
public boolean getFlag(){
return flag;
}
public void setFlag(boolean flag1){
flag = flag1;
}
public void init(){
int flaseNum = 1;
while (flagLogin){
do {
setFlag(true);
System.out.println("欢迎来到团队开发分配管理软件");
System.out.println("请输入想要登陆还是注册");
System.out.println("1.登录");
System.out.println("2.注册");
System.out.println("3.退出");
char ch = Tools.readMenuSelectionUserView();
switch (ch) {
case '1':
boolean flagSgin = SginIn();
if (flagSgin == true){
MainView m = new MainView();
break;
}
if (flaseNum >=5){
System.out.println("错误次数太多程序退出。");
flagLogin = false;
return;
}else {
System.out.println("账号密码不存在,请先注册。");
System.out.println("剩余错误次数:"+(5-flaseNum));
flaseNum++;
}
break;
case '2':
register();
break;
case '3':
System.out.println("确定退出(Y/N):");
char outchar = Tools.readConfirmSelection();
if (outchar == 'Y'){
System.out. println("退出中");
flagLogin = false;
flag = false;
}
break;
}
} while (flag);
}
}
private void register(){ //注册账号,如果账号与我USERS集合内重复的话,则注册失败
System.out.println("开始注册-------");
System.out.println("请输入你的登录账号");
int acount = Tools.readAountAndPassword();
System.out.println("请输入你的登录密码");
int password = Tools.readAountAndPassword();
USER.setAcount(acount);
USER.setPassword(password);
if (isInList(USER)){
return;
}
USERS.add(USER);
// Data.DEFULTUSERSSIZE++;
System.out.println("注册成功");
setFlag(false);
}
private boolean isInList(User user){
for (int i = 0; i < USERS.size(); i++) {
if (user.equals(USERS.get(i))){
System.out.println("用户表中存在该账号重新注册");
return true;
}
}
return false;
}
private boolean SginIn(){ // 登录功能,记录当前登录的用户的账号密码,如果在USERS集合存在则登陆成功。
System.out.println("请输入acount:");
acount = Tools.readAountAndPassword();
System.out.println("请输入password:");
password = Tools.readAountAndPassword();
for (int i = 0; i < USERS.size(); i++) {
int dataAcount = USERS.get(i).getAcount();
int dataPassword = USERS.get(i).getPassword();
if ( acount == dataAcount & password == dataPassword){
USER = USERS.get(i);
System.out.println("登录成功");
setFlag(false);
return true;
}
}
return false;
}
}
5.4.2 Main 类:
package com.team.view;
import com.team.domain.Team;
import com.team.domain.User;
import com.team.service.EmployeeListService;
import com.team.service.TeamListService;
import com.team.service.Tools;
import java.util.ArrayList;
public class MainView {
public static ArrayList<Team> teams;
private static boolean flag = true;
public static EmployeeListService nls ;
public static TeamListService tls;
public MainView () {
nls = new EmployeeListService();
tls = new TeamListService();
teams = new ArrayList<>();
ArrayList<Team> teams = new ArrayList<>();
do {
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.退出软件:");
char option = Tools.readMenuSelectionPro();
switch (option){
case '1':
new UserView();
break;
case '2':
new EmploeesAdministrationView();
break;
case '3':
new TeamView();
break;
case '4':
new ProjectView();
break;
case '5':
flag = false;
LoginView.USER = new User();// 退出的时候重新new一个user回去接收新的用户账号密码。
return;
}
}while (flag);
}
}
5.4.3 USerView 类:
package com.team.view;
import com.team.domain.User;
import com.team.service.Tools;
public class UserView {
private User user;
public UserView(){
user = LoginView.USER;
init();
}
private void init(){
boolean flag = true;
do {
System.out.println("您的账号是:"+user.getAcount());
System.out.println("您的密码是:"+user.getPassword());
System.out.println("欢迎来到用户修改页面");
System.out.println("1.修改账号:");
System.out.println("2.修改密码:");
System.out.println("3.退出");
char option = Tools.readMenuSelectionUserView();
switch (option){
case '1':
System.out.println("1.修改账号");
System.out.println("账号("+ LoginView.USER.getAcount() +"):");
int acount = Tools.readAountAndPassword();
LoginView.USER.setAcount(acount);
System.out.println("修改账号成功");
break;
case '2':
System.out.println("1.修改密码");
System.out.println("密码("+ LoginView.USER.getPassword() +"):");
int password = Tools.readAountAndPassword();
LoginView.USER.setPassword(password);
System.out.println("修改密码成功");
break;
case '3':
System.out.println("是否要退出(Y/N):");
char yorN = Tools.readConfirmSelection();
if (yorN == 'Y'){
flag = false;
}
break;
}
}while (flag);
}
}
5.4.4 EmploeesAdministrationView 类:
package com.team.view;
import com.team.domain.Employee;
import com.team.service.EmployeeListService;
import com.team.service.TeamException;
import com.team.service.Tools;
import java.util.Scanner;
public class EmploeesAdministrationView {
private boolean flag= true;
private static EmployeeListService nls ;
public EmploeesAdministrationView() {
nls= MainView.nls;
init();
}
void init() {
do {
System.out.println("----------开发人员管理主页面------------");
System.out.println("1.开发人员添加");
System.out.println("2.开发人员查看");
System.out.println("3.开发人员修改");
System.out.println("4.开发人员删除");
System.out.println("5.根据id查看");
System.out.println("6. 退出前菜单");
Scanner sc = new Scanner(System.in);
char option = Tools.readMenuSelectionProMax();
switch (option){
case '1':
System.out.println("case1开发人员添加");
nls.addToEmployees();
break;
case '2':
System.out.println("2.开发人员查看");
nls.showAllEmployees();
break;
case '3':
System.out.println("3.开发人员修改");
nls.modify();
break;
case '4':
System.out.println("4.开发人员删除");
System.out.println("请输入想要删除的id:");
int idDelete = Tools.readInt();
try {
nls.remove(idDelete);
}catch (TeamException e ){ // TeamException 为自定义异常类。
System.out.println(e.getMessage());
}
break;
case '5':
System.out.println("请输入想要查找的id");
int getid = Tools.readInt();
try {
nls.getEmployee(getid);
} catch (TeamException e) {
e.getMessage();
}
break;
case '6':
System.out.println("退出前菜单");
flag = false;
}
}while (flag);
}
}
5.4.5 TeamView 类:
package com.team.view;
import com.team.service.EmployeeListService;
import com.team.service.TeamListService;
import com.team.service.Tools;
public class TeamView {
private TeamListService tls ;
private EmployeeListService nls; ;
public TeamView(){
tls = MainView.tls;
nls = MainView.nls;
init();
}
private void init() {
boolean flag = true;
do {
System.out.println("====================");
System.out.println("欢迎来到开发团队管理页面");
System.out.println("====================");
System.out.println("1.添加团队 2.查看团队 3删除团队 4退出 请选择:");
char option = Tools.readMenuSelection();
switch (option){
case '1':
new TeamEmployeesView(); //添加团队页面
break;
case '2':
tls.showAllTeam(); // 查看所有团队
break;
case '3':
tls.delTeam(); //根据团队id删除团队
break;
case '4':
System.out.println("确定退出吗(Y/N):");
char conf = Tools.readConfirmSelection();
if (conf == 'Y'){
flag = false;
}
}
}while (flag);
}
}
5.4.6 ProjectView 类:
package com.team.view;
import com.team.service.ProjectService;
import com.team.service.Tools;
public class ProjectView {
public static ProjectService pros;
public ProjectView() {
pros = new ProjectService();
init();
}
private void init() {
boolean flag = true;
do {
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.退出当前菜单");
char option = Tools.readMenuSelectionPro();
switch (option) {
case '1':
pros.projectAdd(); //项目添加
break;
case '2':
pros.distributionProjectForTeam(); // 项目 分配 根据项目id 和团队的id来分配
break;
case '3':
pros.readProject(); // 查看项目
break;
case '4':
pros.delProject(); // 根据id删除项目
break;
case '5':
System.out.println("确定退出吗(Y/N):");
char yorN = Tools.readConfirmSelection();
if (yorN == 'Y'){
flag = false;
}
break;
}
} while (flag) ;
}
}
5.4.7 TeamEmployeesView 类
package com.team.view;
import com.team.service.EmployeeListService;
import com.team.service.TeamException;
import com.team.service.TeamListService;
import com.team.service.Tools;
public class TeamEmployeesView {
private TeamListService tls ;
private EmployeeListService nls; ;
public TeamEmployeesView(){
tls = MainView.tls;
nls = MainView.nls;
init();
}
private void init() {
boolean flag = true;
do {
System.out.println("====================");
System.out.println("欢迎来到开发人员管理主菜单");
System.out.println("====================");
nls.showAllEmployees();
System.out.println("1.添加程序员到当前团队 2.查看当前团队 3删除当前团队人员 4退出 请选择:");
System.out.println("------------------------------------------------------------------");
char option = Tools.readMenuSelection();
switch (option){
case '1':
System.out.println("请输入想要添加到团队的员工ID:");
int id = Tools.readInt();
try {
tls.addTeamList(tls.getEmployee(id));
} catch (TeamException teamException) {
System.out.println(teamException.getMessage());
}
Tools.readReturn();
break;
case '2':
tls.ShowTeamList();
Tools.readReturn();
break;
case '3':
System.out.println("请输入想要移出团队的员工的团队中的TID:");
// int removeID = TSUtility.readInt();
tls.delTeamList(Tools.readInt());
Tools.readReturn();
break;
case '4':
System.out.println("确定退出吗(Y/N):");
char conf = Tools.readConfirmSelection();
if (conf == 'Y'){
flag = false;
if (tls.getTeam().getProgram().size() != 0){
MainView.teams.add(tls.getTeam());
tls.createNewTeam();
tls.clearMemberId();
}
System.out.println("teamssize:"+MainView.teams.size());
}
break;
}
}while (flag);
}
}
5.5 Service 类
5.5.1 Data 类:
该类是存放默认的员工、用户、和项目数据的类。
package com.team.service;
import com.team.domain.*;
import java.util.ArrayList;
public class Data {
private static int count_Employees =0;//id
public static ArrayList<Employee> DEFULTEMPLOYOEES ;// 存放和默认的 员工的数据。
public static ArrayList<User> USERS ;//存放默认的用户数据
public static ArrayList<Project> DEFULTPROJECT ; // 存放默认的项目数据。
public static int EMPLOYOEESSIZE ; // 因为有默认数据的存在。所以如果向里面添加数据的话,id要从默认数据的末尾的索引自增。
public static int DEFULTUSERSSIZE; //
public static int count_Project = 0;//project id
static {//初始化员工信息 默认员工数据
DEFULTEMPLOYOEES = new ArrayList<>();
DEFULTEMPLOYOEES.add(new Employee(++count_Employees, "马云 ", 22, 3000));
// EMPLOYOEES.add(new Architect(++count_Employees, "马化腾", 32, 18000, Status.FREE, new NoteBook("联想T4", 6000), 60000, 5000));
DEFULTEMPLOYOEES.add(new Programmer(++count_Employees, "李彦宏", 23, 7000, Status.BUSY,new PC("戴尔", "NEC 17寸")));
DEFULTEMPLOYOEES.add(new Programmer(++count_Employees, "刘强东", 24, 7300,Status.VCATION, new PC("戴尔", "三星 17寸")));
DEFULTEMPLOYOEES.add(new Designer(++count_Employees, "雷军 ", 50, 10000, Status.FREE,new Printer("激光", "佳能2900"), 5000));
DEFULTEMPLOYOEES.add(new Programmer(++count_Employees, "任志强", 30, 16800,Status.FREE, new PC("华硕", "三星 17寸")));
DEFULTEMPLOYOEES.add(new Designer(++count_Employees, "柳传志", 45, 35500, Status.FREE, new PC("华硕", "三星 17寸"), 8000));
DEFULTEMPLOYOEES.add(new Architect(++count_Employees, "杨元庆", 35, 6500, Status.FREE, new Printer("针式", "爱普生20k"), 15500, 1200));
DEFULTEMPLOYOEES.add(new Designer(++count_Employees, "史玉柱", 27, 7800, Status.FREE, new NoteBook("惠普m6", 5800), 1500));
DEFULTEMPLOYOEES.add(new Programmer(++count_Employees, "丁磊 ", 26, 6600,Status.FREE, new PC("戴尔", "NEC17寸")));
DEFULTEMPLOYOEES.add(new Programmer(++count_Employees, "张朝阳", 35, 7100,Status.FREE, new PC("华硕", "三星 17寸")));
DEFULTEMPLOYOEES.add(new Designer(++count_Employees, "杨致远", 38, 9600, Status.FREE, new NoteBook("惠普m6", 5800), 3000));
EMPLOYOEESSIZE = DEFULTEMPLOYOEES.size();
}
static {//初始化用户数据。默认密码
USERS = new ArrayList();
USERS.add(new User(123456,123456));
USERS.add(new User(123,123));
DEFULTUSERSSIZE = USERS.size();
}
static {
// 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("------------------------------------------------------------");
DEFULTPROJECT = new ArrayList<>();
DEFULTPROJECT.add(new Project(++count_Project,"小米官网","开发完成类似于小米官网的web项目.",null,false));
DEFULTPROJECT.add(new Project(++count_Project,"公益在线商城","猫宁Morning公益商城是中国公益性在线电子商城.",null,false));
DEFULTPROJECT.add(new Project(++count_Project,"博客系统","博客系统:Java博客系统,让每一个有故事的人更好的表达想法!",null,false));
DEFULTPROJECT.add(new Project(++count_Project,"在线协作文档编辑系统","在线协作文档编辑系统:一个很常用的功能,适合小组内的文档编辑.",null,false));
}
}
5.5.2 EmployeeListService类 :
package com.team.service;
import com.team.domain.*;
import java.util.ArrayList;
/**
* description : 员工管理页面的增删改查
*/
public class EmployeeListService {
public static ArrayList<Employee> employees;
public static int id ;
public EmployeeListService(){//初始化员工数组。从Data内的默认集合内读取数据。
employees = Data.DEFULTEMPLOYOEES;
id = Data.EMPLOYOEESSIZE;
}
public Employee getEmployee() throws TeamException { // 通过id查账员工,如果员工存在则返回该员工的所有信息,如果不存在抛出TeamException异常(id不存在)
System.out.println("请输入想要查找的id");
int getid = Tools.readInt();
for (int i = 0; i < employees.size(); i++) {
if (employees.get(i).getId() == getid){
System.out.println("获取成功");
System.out.println(employees.get(i));
return employees.get(i);
}
}
throw new TeamException("getEmployee:id不存在");
}
private Employee getEmployee(int id) throws TeamException { // 重载上面的方法 用于次Service类自己使用,定义为private,用于修改方法
for (int i = 0; i < employees.size(); i++) {
if (employees.get(i).getId() == id){
System.out.println("获取成功");
System.out.println(employees.get(i));
return employees.get(i);
}
}
throw new TeamException("getEmployee:id不存在");
}
public void modify(){ // 通过id获取想要修改的员工, 如果id不在集合的范围内 或者找不到此id 抛出不存在该员工id异常,存在则修改他们的name age salary值。也可以修改其他的值,这里我就只修改了三个。
System.out.println("请输入想要修改的员工的id:");
int idModify = Tools.readInt();
if (idModify<0 || idModify >employees.size()){
System.out.println("不存在id员工,超出了范围");
return;
}
if (!isExit(idModify)){
System.out.println("不存在该id的员工,可能已经被删除");
return;
}
try {
Employee employeeModify = getEmployee(idModify);
System.out.println("请输入修改想要修改的属性(不修改某项属性enter跳过):");
System.out.print("name("+employeeModify.getName()+"):");
String name = Tools.readString(5,employeeModify.getName());
if (name != employeeModify.getName()){
employeeModify.setName(name);
}
System.out.print("age("+employeeModify.getAge()+"):");
int ageModify = Tools.readModifyInt(3,Integer.toString(employeeModify.getAge()));
if (ageModify != employeeModify.getAge()){
employeeModify.setAge(ageModify);
}
System.out.print("salary("+employeeModify.getSalary()+"):");
double salary = Tools.readModifyDouble(6,Double.toString(employeeModify.getSalary()));
if (salary != employeeModify.getSalary()){
employeeModify.setSalary(salary);
}
} catch (TeamException e) {
e.getMessage();
}
}
private boolean isExit(int id){ // 判断id 是否在我的员工集合内
for (int i = 0; i < employees.size(); i++) {
if (id == employees.get(i).getId()){
return true;
}
}
return false;
}
public void remove () throws TeamException { //通过id来删除员工 不存在则抛出异常
System.out.println("4.开发人员删除");
System.out.println("请输入想要删除的id:");
int idDelete = Tools.readInt();
for (int i = 0; i < employees.size(); i++) {
if (employees.get(i).getId() == id){
employees.remove(i);
System.out.println("删除成功");
return;
}
}
throw new TeamException("remove():id不存在..");
}
public void showAllEmployees(){ // 遍历员工集合
if (employees.size() == 0){
System.out.println("团队内并无成员");
return;
}
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 addToEmployees(){ //通过不同的职位来添加不同 的员工
System.out.println("请选择需要添加的雇员的职位:");
System.out.println("1(无职位)");
System.out.println("2(程序员)");
System.out.println("3(设计师)");
System.out.println("4(架构师)");
int idNum = id;
int numPosition = Tools.readInt();
if (numPosition >4 || numPosition <0){
System.out.println("输入错误请输入1-4");
return;
}
System.out.println("请输入雇员的姓名:");
String name = Tools.readKeyBoard(5,false);
System.out.println("请输入年龄:");
int age = Tools.readInt();
System.out.println("请输入员工的工资:");
double salary = Tools.readDouble();
switch (numPosition){
case 1:
employees.add(new Employee(++id,name,age,salary));
System.out.println("员工添加成功");
break;
case 2:
System.out.println("请为当前程序员配备一台电脑:");
Tools.readReturn();
System.out.println("请输入需要配置PC的型号:");
String model = Tools.readKeyBoard(10,false);
System.out.println("请输入需要配置的PC的显示屏名称");
String display = Tools.readKeyBoard(10,false);
employees.add(new Programmer(++id,name,age,salary,Status.FREE,new PC(model,display)));
System.out.println("Programmer添加成功");
break;
case 3:
System.out.println("请输入该当前设计师的奖金:");
double bonusDesigner = Tools.readDouble();
System.out.println("请为当前设计师配备一台printer:");
Tools.readReturn();
System.out.println("请输入需要配置printer的名字:");
String namePrinter = Tools.readKeyBoard(10,false);
System.out.println("请输入需要配置的printer的类型名称");
String tpye = Tools.readKeyBoard(10,false);
employees.add(new Designer(++id,name,age,salary,Status.FREE,new Printer(namePrinter,tpye),bonusDesigner));
System.out.println("DESigner添加成功");
break;
case 4:
System.out.println("请输入该当前架构师的奖金:");
double bonusArchitect = Tools.readDouble();
System.out.println("请输入该架构师的股份");
int stock = Tools.readStock();
System.out.println("请为当前架构师配备NoteBook:");
Tools.readReturn();
System.out.println("请输入需要配置NoteBook的型号:");
String modelNoteBook = Tools.readKeyBoard(10,false);
System.out.println("请输入需要配置的NoteBook的价格");
double price = Tools.readDouble();
employees.add(new Architect(++id,name,age,salary,Status.FREE,new NoteBook(modelNoteBook,price),bonusArchitect,stock));
System.out.println("架构师添加成功");
break;
}
}
}
5.5.3 TeamListService 类:
package com.team.service;
import com.team.domain.*;
import com.team.view.MainView;
import java.util.ArrayList;
/**
* decription:对Team表的添加查看 删除 团队的操作。
*
* */
public class TeamListService {
public static final int MAXSIZE = 6; // 每个团队最大的一个容量
private int memberId =1; // 在团队内的id
private Team team = new Team();
public void createNewTeam(){
team = new Team();
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}
public void clearMemberId(){
memberId = 1;
}
public void delTeam(){ //根据团队的id 删除团队
System.out.println("请输入想要删除的团队");
int index = Tools.readInt();
if (index-1 <0 || index-1 >=MainView.teams.size()){
System.out.println("没有该团队");
return;
}
MainView.teams.remove(index-1);
System.out.println("删除团队成功");
}
public void showAllTeam(){ //遍历整个所有的团队
if (MainView.teams.size() == 0) {
System.out.println();
System.out.println("---------------当前暂无团队-----------------");
}
System.out.println("---------------团队列表-----------------");
System.out.println("teamid id name age salary ");
for (int i = 0; i < MainView.teams.size(); i++) {
MainView.teams.get(i).setTeamid(i+1);
for (int j = 0; j < MainView.teams.get(i).getProgram().size(); j++) {
// System.out.println("第"+(i+1)+"个团队 "+MainView.teams.get(i).get(j).toStringForTeam());j
// MainView.teams.get(i).setTeamid(j+1);
System.out.println("第"+MainView.teams.get(i).getTeamid()+"个团队 "+MainView.teams.get(i).getProgram().get(j));
}
System.out.println("------------------------------------------------------------");
}
}
public void ShowTeamList(){ //遍历当前团队的成员
System.out.println("请稍后........");
System.out.println("TID/ID\t \t姓名\t \t\t年龄\t \t工资\t \t\t职位\t \t\t奖金");
for (int i = 0; i < team.getProgram().size(); i++) {
System.out.println(team.getProgram().get(i).toStringForTeam());
}
}
private boolean isExit(int id){
for (int i = 0; i < team.getProgram().size(); i++) {
if (team.getProgram().get(i).getId() == id){
return true;
}
}
return false;
}
public void delTeamList(int tid ){//移除团队里的员工
int member = -1;
for (int i = 0; i < team.getProgram().size(); i++) {
if (team.getProgram().get(i).getMemberId() == tid){
member = i;
}
}
System.out.println("确认删除吗(Y(删除)/N(不删除)):");
char ch = Tools.readConfirmSelection();
if (ch == 'Y') {
if (member != -1) {
team.getProgram().get(member).setStatus(Status.FREE);
team.getProgram().remove(member);
System.out.println("该员工已移除团队...");
} else System.out.println("TID不存在");
}
}
public void addTeamList(Employee e) throws TeamException { //添加员工,如果团队等于6则不可以继续添加,如果添加的员工不是程序员架构师和设计师则不能添加,如果该员工的状态不为FREE则不能添加,并且团内最多只能有一个架构师2个设计师,
if (team.getProgram().size() >= 6){
throw new TeamException("成员已满无法添加");
}
//不是员工
if (!(e instanceof Programmer)){
throw new TeamException("该类型为员工不能添加到团队");
}
//员工存在于团队
if (isExit(e.getId())){
throw new TeamException("该员工存在于该团队");
}
//员工在忙
if (((Programmer) e).getStatus() == Status.BUSY){
throw new TeamException("该员工正在忙碌");
}
//一名架构两名设计三名程序员
int numProgrammer =0; int numDesigner = 0; int numArchitect = 0;
for (int i = 0; i < team.getProgram().size(); i++) {
if (team.getProgram().get(i) instanceof Architect){
numArchitect++;
}else if (team.getProgram().get(i) instanceof Designer){
numDesigner++;
}else if (team.getProgram().get(i) instanceof Programmer){
numProgrammer++;
}
}
if (e instanceof Architect){
if (numArchitect>=1){
throw new TeamException("添加失败只能有一个架构师");
}
}else if (e instanceof Designer){
if (numDesigner >=2){
throw new TeamException("添加失败只能有两个设计师");
}
}else if (e instanceof Programmer){
if (numProgrammer >=3){
throw new TeamException("添加失败只能有三名程序员");
}
}
((Programmer) e).setStatus(Status.BUSY);
((Programmer) e).setMemberId(memberId++);
team.getProgram().add((Programmer) e); //加入到团队的员工集合内。
// programmer.setStatus(Status.BUSY);
// System.out.println(programmer.getStatus());
// programmer.setMemberId(memberId++);
// team.add(programmer);
// if (programmer instanceof Architect){
//
// Architect architect = (Architect) e;
// architect.setStatus(Status.BUSY);
// team.add(architect);
// total++;
// } else if (programmer instanceof Designer){
// Designer designer = (Designer) e;
// designer.setStatus(Status.BUSY);
System.out.println("true");/**/
// designer.setStatus(Status.VCATION);
// System.out.println(designer.getStatus());
// team.add(designer);
// total++;
// }
// else if (programmer instanceof Programmer){
// Programmer pro = (Programmer) e;
// pro.setStatus(Status.BUSY);
// team.add(pro);
// total++;
// }
System.out.println("添加到团队成功");
}
public void showTeams(ArrayList<Team> teams){ //遍历团队的集合
for (int i = 0; i < teams.size(); i++) {
System.out.println("ID\t 姓名\t年龄\t 工资\t \t职位\t \t状态\t \t奖金\t\t 股票\t 领用设备");
for (int j = 0; j < teams.get(i).getSize(); j++) {
System.out.println(teams.get(i).getProgram());
}
}
}
public Employee getEmployee(int id) throws TeamException { // 根据获取员工集合里面的员工。
for (int i = 0; i < EmployeeListService.employees.size(); i++) {
if (EmployeeListService.employees.get(i).getId() == id){
System.out.println("获取成功");
System.out.println(EmployeeListService.employees.get(i));
return EmployeeListService.employees.get(i);
}
}
throw new TeamException("getEmployee:id不存在");
}
}
5.5.3 ProjectService 类:
package com.team.service;
import com.team.domain.Project;
import com.team.view.MainView;
import java.util.ArrayList;
/**
* description :对于项目的增删改查。
* */
public class ProjectService {
public static ArrayList<Project> projects ;
static{
projects = new ArrayList<>();
}
public void projectAdd(){ // 对项目的添加,
for (int i = 0; i <Data.DEFULTPROJECT.size() ; i++) {//遍历默认的全部项目
System.out.println(Data.DEFULTPROJECT.get(i));
}
System.out.println("请输入想要添加的项目:");
int projectID = Tools.readInt();
if (projectID-1 <0 ||projectID-1 >=Data.DEFULTPROJECT.size()){
System.out.println("不存在该项目");
return;
}
// TODO: 2022/8/24 添加项目的唯一性 :1.在project内添加id属性。2.或者
for (int i = 0; i < projects.size(); i++) { // 如果项目已经被添加到了项目集合内 则不能重复添加。
if (projectID == projects.get(i).getProjectID()){
System.out.println("该项目已被添加到项目组,请不要重复添加");
return;
}
}
projects.add(Data.DEFULTPROJECT.get(projectID-1));
System.out.println(Data.DEFULTPROJECT.get(projectID-1).getProjectName()+"----------添加成功");
}
public void readProject(){ // 查看项目集合内的项目
if (projects.size() == 0){
System.out.println("项目组内里暂无项目");
return;
}
System.out.println("已添加的项目:");
for (int i = 0; i < projects.size(); i++) {
if (projects.get(i).getTeam() != null){
System.out.println(projects.get(i).toString1());
}else System.out.println(projects.get(i));
if (projects.get(i).isSTATUE() == false){// 如果某个项目的团队为空则表示未被开发(也可以用status来判断)
System.out.println("该项目未被开发");
}else System.out.println("该项目正在被"+projects.get(i).getTeam()+"开发");
}
}
public void distributionProjectForTeam(){ // 根据项目id和团队的id来自主分配
System.out.println("项目组:");
readProject();
if (projects.size() == 0){
System.out.println("项目组并无项目");
return;
}
System.out.println("团队组:");
MainView.tls.showAllTeam();
System.out.println("请输入需要分配项目的id");
int projectID = Tools.readInt();
if (projectID-1 >= projects.size()|| projectID-1 < 0){
System.out.println("找不到该项目:");
return;
}
System.out.println("请输入需要接手该团队的id:");
int teamID = Tools.readInt();
if (teamID-1 >=MainView.teams.size() ||teamID-1 <0){
System.out.println("找不到该团队");
return;
}
projects.get(projectID-1).setSTATUE(true);
projects.get(projectID-1).setTeam(MainView.teams.get(teamID-1));
}
public void delProject(){ // 删除项目
System.out.println("请输入你想删除的项目:");
int pid = Tools.readInt();
if (pid-1 <0 || pid-1 >=projects.size()){
System.out.println("项目不存在");
return;
}
projects.remove(pid-1);
System.out.println("删除项目成功");
}
}
6. 项目总结:
对于这个项目总的来说,项目的需求是全部完成了,而且还添加了一些新的东西进去,但是还有提升的空间,比如对项目的手动添加功能,以及修改员工的属性我只修改了名字年龄工资,其实也可以修改他们的每个属性,我就没有一一的去实现了,还有就是对数据的保存其实可以保存到mysql但当前还未学到就只有了集合Data类来装默认的数据,总的来说自我感觉完成的还算一般。也还有提升的空间,在这次项目的中,也遇到了很多小问题,例如空指针,索引越界等,慢慢积累然后防止以后再次踩坑。
版权归原作者 我在珠穆朗玛峰看北极熊 所有, 如有侵权,请联系我们删除。