1.首先构建三个包分别为domain(领域),service(服务),view(视图),用来保存创建的各个类
2.首先创建登录注册的服务(loginService)和视图(loginView),创建对应的方法和成员变量
3.再创建一个user作为对象,在登录注册这一模块中,保存对应的账号密码,方便后面进行使用
4.设计开发成员界面
5.在domain中创建Employee(职员),然后创建Programmer(程序员)继承职员类,再创建一个Designer(设计师)类继承于程序员类,再创建对应的Architect(架构师),继承于设计师类,分别设置对应的成员变量和继承关系,重写toString方法,同时注意调用的方法
6.设计一个Equipment的接口,再设计PC(电脑),NoteBook(笔记本),Printer(打印机)来实现接口,同时注意这三个类中的成员变量和方法
7.创建开发成员的服务(NameListService),创建对应的方法和成员变量,与上面的进行连用
8.设计团队界面
9.创建开发团队的服务(TeamService),开发团队视图(TeamView),设置里面的方法和成员变量
10.自定义异常(TeamError),用来解决对应的开发团队存在的逻辑问题
11.项目开发界面
12.创建项目开发服务(ProjectService)以及在Domain中创建一个领域(Project),连用后用Project作为对象在ProjectService中使用
13.总视图(IndexView)以及对应的自定义异常(IndexError),把前面的几个界面的方法调用
部分展示:
TeamService:
package Service;
import Domain.Employee;
import Domain.Programmer;
import View.TSUtility;
import java.util.ArrayList;
public class TeamService {
private int counter = 1;//团队ID
private final int MAX_MEMBER = 5;//开发团队的最大成员数
private Programmer[] team = new Programmer[MAX_MEMBER];
private int total = 0;//团队成员的实际人数
private static ArrayList<Programmer[]> teamList = new ArrayList<>();
public int getMAX_MEMBER() {
return MAX_MEMBER;
}
//返回团队的所有对象
public Programmer[] getTeam() {
Programmer[] team1 = new Programmer[total];
if (team1.length!=0) {
for (int i = 0; i < team1.length; i++) {
team1[i] = team[i];
}
}
return team1;
}
//添加成员
public void addMember(Employee e, int index) throws TeamError {
if (total >= MAX_MEMBER) {
throw new TeamError("团队成员已满,无法添加");
} else {
if (e.getPosition().equals("无") == true) {
if (TeamService.getTeamList().get(TeamService.getTeamList().size()-1)[0] == null){
TeamService.getTeamList().remove(TeamService.getTeamList().size()-1);
}
throw new TeamError("该成员不是开发人员,无法添加");
} else {
int numP = 0;
int numA = 0;
int numD = 0;
//判断是否在本团队还是在别的团队中
for (int x = 0; x < getTeam().length; x++) {
if (e.getId() == getTeam()[x].getId()) {
throw new TeamError("该成员已经在该团队中");
} else if (e.getId() != getTeam()[x].getId() & ((Programmer) e).isStatus() == false) {
throw new TeamError("该成员已经在别的团队中");
}
}
//计算团队中有几个开发成员
for (int x = 0; x < getTeam().length; x++) {
if (getTeam()[x].getPosition().equals("架构师") == true) {
numA++;
}
if (getTeam()[x].getPosition().equals("设计师") == true) {
numD++;
}
if (getTeam()[x].getPosition().equals("程序员") == true) {
numP++;
}
}
//根据加入的成员职位来判断是否超过需求人数
if (e.getPosition().equals("架构师") == true) {
numA++;
} else if (e.getPosition().equals("设计师") == true) {
numD++;
} else if (e.getPosition().equals("程序员") == true) {
numP++;
}
if (numA > 1) {
throw new TeamError("团队中至多只能有一名架构师");
} else if (numD > 2) {
throw new TeamError("团队中至多只能有两名设计师");
} else if (numP > 3) {
throw new TeamError("团队中至多只能有三名程序员");
}
((Programmer) e).setStatus(false);
((Programmer) e).setMemberId(counter++);
team[total++] = (Programmer) e;
teamList.set(index,getTeam());
}
}
}
//删除成员
public void removeMember(int memberId,int index) throws TeamError {
if (memberId > MAX_MEMBER) {
throw new TeamError("超出团队的成员TID");
} else {
for (int x = 0; x < total; x++) {
if (memberId == team[x].getMemberId()) {
team[x].setStatus(true);
team[x].setMemberId(0);
if ((x + 1) < total) {
team[x] = team[x + 1];
team[x].setMemberId(--counter);
}
teamList.get(index-1)[x] = null;
total--;
}
}
}
}
//返回团队集合
public static ArrayList<Programmer[]> getTeamList() {
return teamList;
}
//添加团队
public void addTeam(int TID) {
if (team.length == 0) {
System.out.println("该团队没有成员,无法添加团队");
} else {
teamList.add(TID, team);
team = new Programmer[MAX_MEMBER];
total = 0;
counter = 1;
}
}
//删除团队
public void removeTeam() {
System.out.println("请输入你要删除第几团队");
int teamID = TSUtility.readInt();
if (teamID <= teamList.size() && teamID >= 1) {
System.out.println("是否确认删除(Y/N):");
char judge = TSUtility.readConfirmSelection();
if (judge == 'Y') {
teamList.remove(teamID - 1);
System.out.println("删除完毕");
} else {
return;
}
} else {
System.out.println("无法找到该团队");
}
}
}
TeamView:
import Domain.Employee;
import Domain.Programmer;
import Service.NameListService;
import Service.TeamError;
import Service.TeamService;
import java.util.ArrayList;
public class TeamView {
//开发团队管理
public static void enterMenu(){
while (true){
System.out.println("-----------------------开发团队管理------------------------");
System.out.println("1.开发人员管理");
System.out.println("2.开发团队管理");
System.out.println("3.退出");
System.out.println("-----------------------------------------------------------");
char function = TSUtility.readMenuSelectionTeam();
switch (function){
case '1'://1.开发人员管理
enterMainMenu();
break;
case '2'://2.开发团队管理
enterTeamMenu();
break;
case '3'://3.退出
return;
}
}
}
private static NameListService listSvc = new NameListService();
private static TeamService teamSvc = new TeamService();
//团队成员管理
public static void enterMainMenu(){
while (true) {
System.out.println("---------------团队成员管理---------------");
listAllEmployees();
System.out.println("-----------------------------------------");
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4):");
char function = TSUtility.readMenuSelection();
switch (function) {
case '1'://1-团队列表
getTeam();
break;
case '2'://2-添加团队成员
try {
addMember();
} catch (TeamError teamError) {
System.out.println(teamError.getMessage());
}
break;
case '3'://3-删除团队成员
try {
deleteMember();
}catch (TeamError teamError){
System.out.println(teamError.getMessage());
}
break;
case '4'://4-退出
System.out.println("确认退出吗(Y/N)");
char exit = TSUtility.readConfirmSelection();
if (exit == 'Y'){
return;
}else {
break;
}
}
}
}
//查看所有成员的信息
public static void listAllEmployees() {
listSvc.lookEmployees();
}
//获取团队成员列表
public static void getTeam() {
if (teamSvc.getTeamList().size() == 0) {//如果集合的长队为0则打印下面
System.out.println("还没有创建团队");
} else {//遍历团队集合
for (int i = 0; i < teamSvc.getTeamList().size(); i++) {
System.out.println("-------------第" + (i + 1) + "团队---------------");
System.out.println("TID\t\tID\t\t姓名\t\t\t年龄\t\t\t工资\t\t\t职位\t\t\t待机状态\t\t\t奖金\t\t\t分红\t\t\t设备");
for (int x = 0; x < teamSvc.getTeamList().get(i).length; x++) {
if (teamSvc.getTeamList().get(i)[x] != null){
System.out.print(teamSvc.getTeamList().get(i)[x].getMemberId()+"\t\t");
System.out.println(teamSvc.getTeamList().get(i)[x]);
}
}
System.out.println("----------------------------------");
}
}
}
//添加成员
public static void addMember() throws TeamError {
System.out.println("请输入你要添加到那一组团队中(如果还没有创建团队,则输入1会为你创建一个团队):");
int TID = TSUtility.readInt();//第几团队
System.out.println("请输入你要添加的成员ID:");
int ID = TSUtility.readInt();//员工ID
ArrayList<Employee> em = NameListService.getAllEmployees();//使用NameListService.getAllEmployees()方法来得到集合
if (teamSvc.getTeamList().size() == 0) {//如果一开始没有团队,则创建一个团队
teamSvc.addTeam(0);
}
if (TID <= teamSvc.getTeamList().size() & TID > 0) {//如果TID小于等于团队集合的长度,并且大于0
for (int x = 0; x < em.size(); x++) {
if (em.get(x).getId() == ID) {//输入的ID与集合中的ID匹配
teamSvc.addMember(em.get(x), TID - 1);//使用teamSvc.addMember的方法添加成员em.get(x)为集合对应的数据,TID - 1为TID对应的索引值
System.out.println("添加完毕");
return;
}else if (em.get(x).getId() != ID & x==em.size()-1){//如果输入的ID与集合中的ID不匹配,并且直到最后都么有对上
System.out.println("找不到该成员");
if (TeamService.getTeamList().get(TeamService.getTeamList().size()-1)[0] == null){//如果团队集合的最后一位的数据为null则删除该团队
TeamService.getTeamList().remove(TeamService.getTeamList().size()-1);
}
}
}
} else {//TID不在存在的团队集合的范围内
System.out.println("该团队不存在");
}
}
//删除成员
public static void deleteMember() throws TeamError {
System.out.println("请输入你要在那个团队删除成员:");
int index = TSUtility.readInt();
System.out.println("请输入你要删除的成员TID:");
int TID = TSUtility.readInt();
if (index <= teamSvc.getTeamList().size() & index > 0) {
Programmer[] te = teamSvc.getTeamList().get(index - 1);
for (int x = 0; x < te.length; x++) {
if (((Programmer) te[x]).getMemberId() == TID) {
teamSvc.removeMember(TID,index);
System.out.println("删除完毕");
}
}
} else {
System.out.println("你输入的团队还不存在");
}
}
//团队调度界面
public static void enterTeamMenu(){
while (true){
System.out.println("---------------------团队调度界面------------------------");
getTeam();
System.out.println("--------------------------------------------------------");
System.out.print("1-添加团队 2-查看团队 3-删除团队 4-退出 请选择(1-4):");
char judge = TSUtility.readMenuSelection();
switch (judge){
case '1'://1-添加团队
try {//处理异常
addTeam();
}catch (TeamError teamError){
System.out.println(teamError.getMessage());
}
break;
case '2'://2-查看团队
getTeam();
break;
case '3'://3-删除团队
teamSvc.removeTeam();
break;
case '4'://4-退出
System.out.println("确定退出吗(Y/N)");//判断是Y还是N执行以下
char exit = TSUtility.readConfirmSelection();
if (exit == 'Y'){
return;
}else {
break;
}
}
}
}
//添加团队
public static void addTeam() throws TeamError {
//添加团队成员
System.out.println("请先添加团队成员:");
ArrayList<Employee> em = NameListService.getAllEmployees();//使用listSvc的getAllEmployees方法
teamSvc.addTeam(teamSvc.getTeamList().size());
boolean flag = true;
for (int x = 0 ; x < teamSvc.getMAX_MEMBER();x++ ){
System.out.println("请输入你要添加的成员");
int men = TSUtility.readInt();
for (int i = 0 ; i <em.size();i++) {
if (em.get(i).getId() == men) {
teamSvc.addMember(em.get(i), TeamService.getTeamList().size()-1);
break;
}else if (i == em.size()-1 && em.get(i).getId() != men){
System.out.println("未找到该成员");
flag = false;
continue;
}
}
if (flag) {
System.out.println("请问是否足够");
char judge = TSUtility.readConfirmSelection();
if (judge == 'Y') {
if (TeamService.getTeamList().get(TeamService.getTeamList().size() - 1)[0] == null) {
TeamService.getTeamList().remove(TeamService.getTeamList().size() - 1);
}
return;
} else {
continue;
}
}
}
}
}
工具包:
import java.util.Random;
import java.util.Scanner;
public class TSUtility {
private static Scanner scanner = new Scanner(System.in);
//1-4选择
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;
}
//1-5选择
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 readMenuSelectionLogin() {
char c;
for (; ; ) {
String str = readKeyBoard(1, true);
if(str.equals("")){
c='0';
}else {
c = str.charAt(0);
}
if (c != '1' && c != '2' &&
c != '3' | c == 32) {
System.out.print("选择错误,请重新输入:");
} else {
break;
}
}
return c;
}
public static char readMenuSelectionTeam() {
char c;
for (; ; ) {
String str = readKeyBoard(1, true);
if(str.equals("")){
c='0';
}else {
c = str.charAt(0);
}
if (c != '1' && c != '2' &&
c != '3' ) {
System.out.print("选择错误,请重新输入:");
} else {
break;
}
}
return c;
}
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
public static int readInt() {//不带返回int
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
if (n<0){
System.out.println("请输入正数:");
continue;
}
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);
if (n<0){
System.out.println("请输入正数:");
continue;
}
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static Double readDouble(double defaultValue) {
Double n;
for (; ; ) {
String str = readReturn(6, true);
if (str.equals("")) {
return defaultValue;
}
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 = readReturn(limit, true);
return str.equals("")? defaultValue : str;
}
public static String readString(int limit, String defaultValue,boolean flag) {
String str = readReturn(limit, true);
return str.equals("")? "" : str;
}
public static String readReturn(int limit, boolean blankReturn) {
String line1 = "";
while (scanner.hasNextLine()) {
line1 = scanner.nextLine();
if (line1.length() == 0) {
if (blankReturn) return line1;
else continue;
}
if (line1.length() < 1 || line1.length() > limit) {
System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
continue;
}
break;
}
return line1;
}
public static String readKeyBoard(int limit, boolean blankReturn) {
String line = "";
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if (line.equals("")){
System.out.print("未检测到信息,请重新输入:");
continue;
}
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");
}
}
public static int readInt(int defaultValue) {
int n;
for (; ; ) {
String str = readReturn(11, true);
if (str.equals("")) {
return defaultValue;
}
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
}