After that, there will be a summary and perfect version.
Module division:
The successful demonstration of a project requires the planning of three modules.
There are three modules: user interaction layer, logical operation layer and entity layer.
The user interaction layer is the main control module, including the design and display of the operation interface. The logical operation layer is to design and realize the functions of users, teams and projects (including user registration and login, addition, deletion, modification and query, addition, deletion, modification and query of teams and projects). The entity layer includes the attributes of each entity class in the whole project.
Therefore, create a large package com. Com under the src module in the IDE Team and three small packages, which are com team. domain,com.team.service,com.team. Three small bags.
As shown in the figure:
Physical layer:
The entity layer includes eight entity classes and an interface:
Logical operation layer:
It includes logical operations such as login with registration, addition, deletion, modification and query of users and projects and teams.
The interface interaction layer includes six classes. The main program indexView connects the four modules of LoginView, NamelistView, ProjectView and TeamView together, and TSUtility is responsible for controlling the length of input instructions and various prompts at the control console.
Design idea:
The first is the addition, deletion, modification and query of team personnel:
1. Realize the function of adding team
View current team member list subfunction
Add team member subfunction (the status of the developer will change to false after adding)
Delete the team member subfunction (the status of the developer will change to true after deletion)
2. Realize the function of viewing team
List all teams and give tips when there are no teams.
3. Realize the function of deleting team
Give a prompt when there is no team or the team number entered by the user is incorrect; After deletion, the status of all members of the team should change to true.
The add team member subfunction contains the following failure information: (you need to throw a custom exception)
The member is full and cannot be added
The member is not a developer and cannot be added
The employee has been in the development team
The employee is already a member of a team
There can be at most one architect in the team (instanceof can be used for the following judgment)
There can be no more than two designers in the team
There can be no more than three programmers on the team
Custom exception:
Β
The TeamService class contains 10 methods. The first is three main function implementation methods: addTeam method is to add a team, getAllTeam method is to view a team, and removeTeam method is to delete a team.
Then there are the implementation methods of the three sub functions in the add team main function: getTeam method is to realize the sub function of viewing the current team member list, addMember method is to realize the sub function of adding team members (in this method, pay attention to throwing corresponding custom exceptions according to different situations), and removeMember method is to realize the sub function of deleting team members.
Finally, there are four team member judgment methods that are private and can only be called by the addMember method of this class. Their function is to judge the composition of team members so as to throw exceptions. isBelongTeam method is to judge whether the member object to be added is in the current team; isHaveArchitect method is to judge whether there is an architect in the current team when the member object to be added is an architect; isHaveDesigner method is to judge whether there are two designers in the current team when the member object to be added is a designer; isHaveProgrammer method is to judge whether there are three programmers in the current team when the member object to be added is a programmer.
Β
package com.team.service; import com.team.domain.Architect; import com.team.domain.Designer; import com.team.domain.Employee; import com.team.domain.Programmer; import com.team.view.TSUtility; import java.util.ArrayList; public class TeamService { private static int counter = 1; //It is used to automatically generate the unique ID in the team, that is, memberId, for new members in the development team private final int MAX_MEMBER = 5; //Maximum number of development team members private Programmer[] team = new Programmer[MAX_MEMBER]; //Used to save the member objects in the current team private int total = 0; //Record the actual number of current team members private ArrayList<Programmer[]> allTeam = new ArrayList<>(); //Used to save all teams //Add team (add team function in team scheduling interface) public void addTeam() { if (getTeam().length == 0) { System.out.println("You have not added members for the current team, failed to add team!"); return; } allTeam.add(getTeam()); team = new Programmer[MAX_MEMBER]; total = 0; counter = 1; } //View team (view team function in team scheduling interface) public ArrayList<Programmer[]> getAllTeam() { return allTeam; } //Delete team (delete team function in team scheduling interface (parameter: number of the team to be deleted; exception: there is no such team, deletion failed)) public void removeTeam(int teamNumber) throws TeamException { if (teamNumber < 1 || teamNumber > allTeam.size()) { throw new TeamException("There is no such team, please input normally! At present, the team has only" + allTeam.size() + "individual"); } else { System.out.print("Confirm whether to delete(Y/N): "); if (TSUtility.readConfirmSelection() == 'N') { throw new TeamException("Please consider clearly!"); } else { for (Programmer p : allTeam.get(teamNumber - 1)) { p.setStatus(true); } allTeam.remove(teamNumber - 1); } } } /* The following three methods (getTeam, addMember and removeMember) belong to the sub functions of adding team functions in the team scheduling interface */ //Team member list (return all member objects of the current team) public Programmer[] getTeam() { Programmer[] team = new Programmer[total]; for (int i = 0; i < total; i++) { team[i] = this.team[i]; } return team; } //Add team member (parameter: object to be added; exception: failed to add, and the reason for failure is included in TeamException) public void addMember(Employee e) throws TeamException { if (total == MAX_MEMBER) { throw new TeamException("The member is full and cannot be added"); } else if (!(e instanceof Programmer)) { throw new TeamException("The member is not a developer and cannot be added"); } else if (isBelongTeam(e)) { throw new TeamException("The employee has been in the development team"); } else if (!((Programmer) e).isStatus()) { throw new TeamException("The employee is already a member of a team"); } else if (isHaveArchitect(e)) { throw new TeamException("There can be at most one architect on the team"); } else if (isHaveDesigner(e)) { throw new TeamException("There can be no more than two designers in the team"); } else if (isHaveProgrammer(e)) { throw new TeamException("There can be no more than three programmers on the team"); } else { Programmer p = (Programmer) e; team[total++] = p; p.setMemberId(counter++); p.setStatus(false); } } //Delete team member (parameter: memberId of the member to be deleted; exception: unable to find the employee with the specified memberId, deletion failed) public void removeMember(int memberId) throws TeamException { if (memberId < 1 || memberId > total) { throw new TeamException("You entered TID Error, deletion failed!"); } else { team[memberId - 1].setStatus(true); for (int i = memberId - 1; i < total; i++) { if (i == total - 1) { team[i] = null; } else { team[i] = team[i + 1]; team[i].setMemberId(team[i].getMemberId() - 1); } } total--; counter--; } } /* The following four methods (isBelongTeam, isHaveArchitect, isHaveDesigner and isHaveProgrammer) can only be called by the addMember method of this class */ //Judge whether the member object to be added is in the current team private boolean isBelongTeam(Employee e) { for (int i = 0; i < total; i++) { if (e.getId() == team[i].getId()) { return true; } } return false; } //When the member object to be added is an architect, judge whether there is already an architect in the current team private boolean isHaveArchitect(Employee e) { if (e instanceof Architect) { for (int i = 0; i < total; i++) { if (team[i] instanceof Architect) { return true; } } } return false; } //When the member object to be added is a designer, judge whether there are already two designers in the current team private boolean isHaveDesigner(Employee e) { int count = 0; if (e instanceof Designer && !(e instanceof Architect)) { for (int i = 0; i < total; i++) { if (team[i] instanceof Designer && !(team[i] instanceof Architect)) { count++; } } return count >= 2; } return false; } //When the member object to be added is a programmer, judge whether there are already three programmers in the current team private boolean isHaveProgrammer(Employee e) { int count = 0; if (e instanceof Programmer && !(e instanceof Designer)) { for (int i = 0; i < total; i++) { if (!(team[i] instanceof Designer)) { count++; } } return count >= 3; } return false; } }
Addition, deletion, modification and query of items:
1. Realize the adding function of the project
Add according to the given reference items (the same item cannot be added repeatedly).
2. Realize the function of project allocation and development team
The project is randomly assigned to an idle development team (if there is no idle team, corresponding prompt shall be given, and if there is no added project, corresponding prompt shall also be given).
3. Realize the view function of the project
You can view the relevant information of all projects and the development status of the project (no corresponding prompt is given for adding projects).
4. Realize the function of deleting items
Undeveloped projects can be deleted (projects under development cannot be deleted).
There are three classes related to the development Project management module: Project, ProjectService and ProjectView.
The ProjectService class contains six methods. The first four are the main methods. addProject method is to add the project, dealingPro method is to allocate the development team, getPro method is to view the project, and delPro method is to delete the project. The last two are auxiliary methods. The isNotDeveloped method is used to judge whether there are undeveloped projects, and the isAdded method is used to judge whether the projects have been added to the collection (this method is private and can only be called by the addProject method of this class)
Main program running interface:
After writing the four modules of the program, we need to connect the four modules to form a complete program, and write the main operation interface for the program, so we need to write an IndexView class. The code is as follows:
package com.team.view; /* Software main interface class (connecting four modules together) */ public class IndexView { private static LoginView lv = new LoginView(); private static NameListView nlv = new NameListView(); private static TeamView tv = new TeamView(); private static ProjectView pv = new ProjectView(); /* Color effects */ public static final String ANSI_RESET = "\u001B[0m"; public static final String ANSI_BLUE = "\u001B[34m"; public static void main(String[] args) { IndexView iv = new IndexView(); lv.initMenu(); iv.softwareMainMenu(); } //Software main menu private void softwareMainMenu() { while (true) { System.out.println(ANSI_RESET + ANSI_BLUE); System.out.println("π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£"); System.out.println("π£ π£"); System.out.println("π£ ~Software main menu~ π£"); System.out.println("π£ π£"); System.out.println("π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£π£"); System.out.println("π»1. <User information modification> *"); System.out.println("π2. <Developer management> *"); System.out.println("π¦3. <Development team scheduling management> *"); System.out.println("π»4. <Development project management> *"); System.out.println("π¦5. <Exit software> *"); System.out.println("β¬Please select: "); System.out.print(ANSI_RESET); switch (TSUtility.readMenuSelectionPro()) { case '1': lv.modifyMenu(); break; case '2': try { TSUtility.loadSpecialEffects(); } catch (InterruptedException e) { e.printStackTrace(); } nlv.DeveloperManageMainMenu(); break; case '3': tv.developTeamMainMenu(); break; case '4': pv.projectManageMainMenu(); break; case '5': System.out.print("Confirm whether to exit(Y/N): "); if (TSUtility.readConfirmSelection() == 'Y') { System.exit(0); } break; } } } }
The specific details will be posted in the next detailed and complete article.
Β