1, Order
For those of us who write articles, the preface itself is a place to start the article. Today, when I write this software article (referred to as soft article for short), I would not have written a preface, but this article is still of great significance to me. I suddenly want to write a preface.
Many times people look back on the moment of their life to understand that maybe they only made a small decision in a certain period of time, but that may be the fork in the road of great changes in fate.
Left or right are between their own thoughts, and then made a decision, and rushed to the unknown future without hesitation. But at that time, I thought it was just a very ordinary day in my life.
The sun will still rise as usual, and I have jumped into the sea of programming. I don't swim back to the unknown distance. I don't know the wind and rain. No one is the same in this world, and everyone is the same. I study java purely for high wages and not to be eliminated by this era. Maybe other industries have a bright future, but in my world view, computers are the only way for human beings to link the universe.
Finally, I would like to say that Haruki Murakami said, "there is no right choice in this world. We just have to work hard to make the original choice right."
2, Introduction
This is the first complex general project I came into contact with. I have done array management software and collection customer information management software before. However, in this project, the development of distribution software by the project team needs to apply object-oriented encapsulation and inheritance of polymorphic knowledge and array collection data type conditional loop, You need to understand the static modifiers of code blocks and all the previous knowledge to make your head grow. Fortunately, I learned while watching and did it. I got it out. All the bugs I found have been debugged. Now I'll send out the code and process. Let's have a look and give some advice.
3, Project requirements
1. Objectives:
(1) Simulate and implement a text-based interface project development team allocation management software
(2) Be familiar with the advanced object-oriented features of Java, and further master programming and debugging skills
(mainly involving the following knowledge points:
Class inheritance and polymorphism
Object value transfer and interface
static and final modifiers
Use of special classes: wrapper class, abstract class and inner class exception handling
Java basic syntax and process control
Array, ArrayList set)
2. Requirements Description:
The software realizes the following functions:
When the software starts, first enter the login interface for registration and login functions.
After successful login, you can enter the menu to modify the developer account and password first.
Then you can add, delete and modify developers
After adding personnel successfully, according to the menu prompt, set up a development team based on the existing company members to develop a new project.
The build process includes inserting a member into the team or deleting a member from the team. It can also list the existing members in the team. The development team members include architects, designers and programmers.
If the team is successfully established, you can enter the project module, add projects, and assign development teams to develop.
3. Software design structure:
The software consists of the following three modules:
com.team.view The module is the main control module, which is responsible for menu display and user operation
com.team.service The module is the management module of entity objects (Employee and its subclasses, such as programmers)
NameListService and TeamService classes use their own arrays to manage company employee and development team member objects respectively
ProjectService is the operation object class for the project
The domain module is the package of JavaBean classes such as Employee and its subclasses
4, Development and Implementation
1. User registration and login module
Define a LoginView class
Implementation registration method
If you don't have an account, you need to register
If you have an account, log in directly
Realize login function
Judge whether the value entered by the user is correct
If correct, enter the software menu
If there is an error, re-enter. The limit is only 5 times. If the number exceeds, the program stops and restarts
Realize the function of modifying user password
You can modify the user name, password, or both.
2. Developer management module
(1) . complete the entity class creation of each class in the domain package
The com.team.domain module contains all entity classes:
Among them, programmers and their subclasses will receive some electronic equipment (Interface).
Under IDEA, the package domain in the module I created is as follows:
(project is the class required later)
Design of Equipment interface and its implementation subclass
explain:
Model indicates the model of the machine
Display indicates the name of the display
Type indicates the type of machine
Provide the get/set method of each attribute and overload constructor as required
The implementation class implements the methods of the interface and returns the information of their respective properties
Design of Employee class and its subclasses
explain:
memberId is used to record the ID of a member in the development team after joining the team
Status is the status of personnel in the project. It is first assigned to true and false when added to the team
Equipment indicates the equipment collected by the member
You can provide the get/set method of each attribute and overload constructor for the class as needed
Bonus means bonus
stock indicates the number of shares awarded by the company
You can provide the get/set method of each attribute and overload constructor for the class as needed
(2) . complete the entity operation creation of each application class (service) in the service package
Complete the function operation in the NameListService class
Realize the addition of employees (according to occupation (none, programmer, designer, architect))
Realize the modification of employees (at least modify the name, age and salary of employees)
Delete the employee (note that the employee id needs to be displayed dynamically, that is, the employee id needs to be updated after deletion)
Enable employees to view (display all data)
Design of NameListService class
explain:
getAllEmployees() method: get all current employees.
Return: contains all employee sets
Getemployee (ID: int) method: get the employee object with the specified ID.
Parameter: Specifies the ID of the employee
Return: specify employee object
Exception: the specified employee cannot be found
Provide a custom exception class under the service sub package: TeamException
In addition, you can add other methods or overload constructors as needed
Write the NameListService class according to the design requirements
One attribute is: private ArrayList < employee > employees
A code block is used to fill in the data, as shown in the figure (note that different people have different identities and devices)
There is a method: getAllEmployees(), just return the employees object
There is another method: getEmployee(int id). If you get the employee with the specified id, you will throw a custom exception.
Other methods
3. Development team scheduling management module
Please see the following requirements description:
The team interface displays the list of company members (these are the default values, please implement them in the developer management module), as follows:
Requirements Description:
If the add operation fails for some reason, the following information will be displayed (the failure reason varies depending on the specific reason):
1 - Team List 2 - add team members 3 - delete team member 4 - exit Please select (1-4):
Failure information includes the following: (custom exception needs to be thrown)
The member is full and cannot be added
The member is not a developer and cannot be added
The employee is already in the development team
The employee is already a member of a team
There can be no more than one architect in the team (the following judgment can be made by using instanceof)
There can be no more than two designers on the team
There can be no more than three programmers on the team
Requirements Description:
When the add team member menu is selected, the function of adding specified (by ID) members from the list to the development team is performed:
After adding successfully, press enter to re display the main interface.
Requirements for personnel composition of development team:
Up to one architect
Up to two designers
Up to three programmers
Requirements Description:
When the delete team member menu is selected, the function of deleting the specified (through TeamID) member from the development team is performed:
After the deletion is successful, press enter to re display the main interface.
Requirements Description:
When you select the team list menu, existing members of the development team are listed, for example:
1 - Team List 2 - add team members 3 - delete team member 4 - exit Please select (1-4): 1
--------------------Team member list---------------------
TDI/ID full name Age Wages Position Bonus Stock
2/4 Qiang Dong Liu twenty-four seven thousand and three hundred programmer
3/2 Ma Huateng thirty-two eighteen thousand Architect fifteen thousand two thousand
4/6 Ren Zhiqiang twenty-two six thousand and eight hundred programmer
5/12 Zhi Yuan Yang twenty-seven six hundred designer four thousand and eight hundred
-----------------------------------------------------
Design of TeamService class:
Function: management of development team members: add, delete, etc. (it also needs to be implemented by itself).
explain:
counter is a static variable, which is used to automatically generate a unique ID in the team, that is, memberId, for new members in the development team. (Note: add 1 should be used)
MAX_MEMBER: indicates the maximum number of members of the development team
Team array: used to save the member objects in the current team (or a new collection)
total: record the actual number of team members
Design of TeamService class:
getTeam() method: returns all objects of the current team
Return: an array containing all member objects. The size of the array is consistent with the number of members
addMember(e: Employee) method: add members to the team
Parameter: object to add member
Exception: failed to add. TeamException contains the failure reason
removeMember(memberId: int) method: delete a member from the team
Parameter: memberId of the member to be deleted
Exception: the employee with the specified memberId cannot be found, deletion failed
In addition, you can add other methods or overload constructors as needed
Design of TeamView class
explain:
listSvc and teamSvc properties: for methods in classes
enterMainMenu() method: main interface display and control method.
The following methods are only called by the enterMainMenu() method:
listAllEmployees() method: list all members of the company in a table form
getTeam() method: display team member list operation
addMember() method: implements the operation of adding members
deleteMember() method: implements the operation of deleting members
4. Develop project management module
Complete the creation of the Project entity class Project in the domain package
Complete the creation of the project operation class ProjectService in the service package
Other required method properties can be added by yourself
Design of IndexView class
Finally, write the project program in the view package and run the main interface class IndexView
Put the contents of the first four modules together, run the software, operate the basic functions, de bug bugs, and complete the project development.
5, Architecture deployment
If there is no reference code, how should we expand it?
Let's take a look at the system functional structure:
At a glance, we can see that what we need to do is to create four modules and finally harvest them as a whole, so that each descendant can be associated, and the text can run normally without BUG.
So what I suggest is to do it module by module, and then do a good job. Test it with the main method, and finally find a way to gather a pile and let it run!!!!
System process:
6, Code implementation
1. Under domain package:
Employee (employee parent):
package domain; /* *Employee category */ public class Employee{ public int id; public String name; public int age; public double salary;//wages public Employee() { } public Employee(int id, String name, int age, double salary) { this.id = id; this.name = name; this.age = age; this.salary = salary; } //constructor public void setId(int id) { this.id = id; } public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; } public void setSalary(double salary) { this.salary = salary; } public int getId() { return id; } public String getName() { return name; } public int getAge() { return age; } public double getSalary() { return salary; } //method public String getDetails(){ return id+"\t"+name+"\t"+" "+age+"\t\t"+salary; } @Override public String toString() { return getDetails(); } }
programmer class:
package domain; /* *Programmer class */ public class Programmer extends Employee { private int memberld;//It is used to record the ID of a member in the development team after joining the team private boolean status = true;//Status is the status of personnel in the project. It is first assigned to true and false when added to the team public Equipment equipment; public Programmer(int id, String name, int age, double salary, Equipment equipment) { super(id,name,age,salary); this.equipment=equipment; } public Programmer(int id, String name, int age, double salary, int memberld, boolean status, Equipment equipment) { super(id, name, age, salary); this.equipment = equipment; } public Programmer() { } public int getMemberId() { return memberld; } public void setMemberId(int memberId) { this.memberld = memberId; } public Boolean getStatus() { return status; } public void setStatus(Boolean status) { this.status = status; } public Equipment getEquipment() { return equipment; } public void setEquipment(Equipment equipment) { this.equipment = equipment; } protected String getMemberDetails() { return getMemberId() + "/" + getDetails(); } public String getDetailsForTeam() { return getMemberDetails() + "\t programmer"; } @Override public String toString() { return getDetails() + "\t programmer\t" + status + "\t\t\t\t\t" + equipment.getDescription(); } }
Designer (designer class):
package domain; /* *designer */ public class Designer extends Programmer{ public double bonus;//bonus public Designer() { } public Designer(int id, String name, int age, double salary, Equipment equipment, double bonus) { super(id, name, age, salary, equipment); this.bonus = bonus; } public double getBonus() { return bonus; } public void setBonus(double bonus) { this.bonus = bonus; } @Override public String getDetailsForTeam() { return getMemberDetails()+"\t designer\t"+getBonus(); } @Override public String toString() { return getDetails() + "\t designer\t" + getStatus() + "\t" + getBonus() +"\t\t\t" + getEquipment().getDescription(); } }
Architect (architect class):
package domain; /* *Architect class */ public class Architect extends Designer{ public int stock;//Number of shares awarded by the company public Architect(){ } public Architect(int id, String name, int age, double salary, Equipment equipment, double bonus, int stock) { super(id, name, age, salary, equipment, bonus); this.stock = stock; } public int getStock() { return stock; } public void setStock(int stock) { this.stock = stock; } @Override public String getDetailsForTeam() { return getMemberDetails() + "\t architect \t" + getBonus() + "\t" + getStock(); } @Override public String toString() { return getDetails() + "\t architect \t" + getStatus() + "\t" + getBonus() + "\t" + getStock() + "\t" + getEquipment().getDescription(); } }
Interface Equipment:
package domain; /* *Interface */ public interface Equipment {//Electronic equipment String getDescription();//type }
Interface implementation class Notebook (laptop):
package domain; import view.TSUtility; /* *Notebook computer */ public class NoteBook implements Equipment { public String model;//Model of the machine public double price;//Price public NoteBook() { super(); } public NoteBook(String model, double price) { super(); 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; } public NoteBook addNoteBook(){ System.out.println("Please enter the model of the laptop to be configured"); String model= TSUtility.readKeyBoard(10,false); System.out.println("Please enter the price of the laptop to be configured(No more than six digits)"); double price=TSUtility.readDouble(); System.out.println("Device added successfully!"); return new NoteBook(model,price); } @Override public String getDescription() { return model+"("+price+")"; } }
Interface implementation class PC (desktop computer):
package domain; /* Desktop computer */ import view.TSUtility; public class PC implements Equipment{ public String model;//Machine model public String display;//Display name public PC() { super(); } public PC(String model, String display) { super(); 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; } public PC addPC(){ System.out.println("Please enter the model of the desktop computer you need to configure"); String model= TSUtility.readKeyBoard(10,false); System.out.println("Please enter the name of the desktop display you need to configure"); String display=TSUtility.readKeyBoard(10,false); System.out.println("Device added successfully!"); return new PC(model,display); } @Override public String getDescription() { return model+"("+display+")"; } }
Interface implementation class Printer (Printer):
package domain; import view.TSUtility; import java.time.format.TextStyle; /* *printer */ public class Printer implements Equipment{ public String name; public String type;//Machine type public Printer() { } 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; } public Printer addPrinter(){ System.out.println("Please enter the name of the printer you need to configure"); String name= TSUtility.readKeyBoard(10,false); System.out.println("Please enter the printer machine type you need to configure"); String type=TSUtility.readKeyBoard(10,false); System.out.println("Device configuration succeeded!"); return new Printer(name,type); } @Override public String getDescription() { return name+"("+type+")"; } }
project entity class:
package domain; /* Project entity class */ import java.util.Arrays; public class Project { private int proId;//Item No private String projectName;//entry name private String desName;//Project description private Programmer[] team;//the development team private String teamName;//Development team name private boolean status=false;//Development status (true means developing, false means undeveloped) public Project() { } public Project(int proId, String projectName, String desName, Programmer[] team, String teamName, boolean status) { this.proId = proId; this.projectName = projectName; this.desName = desName; this.team = team; this.teamName = teamName; this.status = status; } public int getProId() { return proId; } public void setProId(int proId) { this.proId = proId; } public String getProjectName() { return projectName; } public void setProjectName(String projectName) { this.projectName = projectName; } public String getDesName() { return desName; } public void setDesName(String desName) { this.desName = desName; } public Programmer[] getTeam() { return team; } public void setTeam(Programmer[] team) { this.team = team; } public String getTeamName() { return teamName; } public void setTeamName(String teamName) { this.teamName = teamName; } public boolean isStatus() { return status; } public void setStatus(boolean status) { this.status = status; } public String des(){ return "Project project{" + "proId Item No=" + proId + ", projectName entry name='" + projectName + '\'' + ", desName Project description='" + desName + '\'' + ", team the development team=" + Arrays.toString(team) + ", teamName Development team name='" + teamName + '\'' + ", status Development team status=" + status + '}'; } @Override public String toString() { des(); if (status){ return "Project[" + projectName + "]"+ "---->Being used by the team[" + teamName + "]Under development!"; }else { return des()+"Project[" + projectName + "]---->"+ "Not developed!"; } } }
2. Under service package:
Exception class TeamException:
package service; public class TeamException extends Exception{ public TeamException(){} public TeamException(String message) { super(message); } }
Developer management class NameListService:
package service; /* Developer management module */ import domain.*; import view.TSUtility; import java.util.ArrayList; public class NameListService { //Set of employees private ArrayList<Employee> employees = new ArrayList<Employee>(); //Add employee ID private int count = 1; //Initialize defaults (code block) { employees.add(new Employee(count, "Jack Ma ", 22, 3000)); employees.add(new Architect(++count,"pony ",32,18000,new NoteBook("association T4",6000),60000,5000)); employees.add(new Programmer(++count, "Robin Li", 23, 7000, new PC("Dale", "NEC 17 inch"))); employees.add(new Programmer(++count, "Qiang Dong Liu", 24, 7300, new PC("Dale", "Samsung 17 inches"))); employees.add(new Designer(++count, "Lei Jun ", 50, 10000, new Printer("laser", "Canon 2900"), 5000)); employees.add(new Programmer(++count, "Ren Zhiqiang", 30, 16800, new PC("ASUS", "Samsung 17 inches"))); employees.add(new Designer(++count, "Liu Chuanzhi", 45, 35500, new PC("ASUS", "Samsung 17 inches"), 8000)); employees.add(new Architect(++count, "Yang Yuanqing", 35, 6500, new Printer("Needle type", "Epson 20 k"), 15500, 1200)); employees.add(new Designer(++count, "Shi Yuzhu", 27, 7800, new NoteBook("HP m6", 5800), 1500)); employees.add(new Programmer(++count, "Ding Lei ", 26, 6600, new PC("Dale", "NEC17 inch"))); employees.add(new Programmer(++count, "Chao Yang Zhang ", 35, 7100, new PC("ASUS", "Samsung 17 inches"))); employees.add(new Designer(++count, "Zhi Yuan Yang", 38, 9600, new NoteBook("HP m6", 5800), 3000)); } public NameListService() { } public NameListService(ArrayList<Employee> employees, int count) { this.employees = employees; this.count = count; } public ArrayList<Employee> getEmployees() { return employees; } public void setEmployees(ArrayList<Employee> employees) { this.employees = employees; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } //Get all employee data sets public ArrayList<Employee> getAllEmployees() { return employees; } //Get current employee 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("The employee does not exist"); } public void addEmployee(){ System.out.println("Please enter the position of the employee to be added:"); System.out.println("1(No position)"); System.out.println("2(programmer)"); System.out.println("3(designer)"); System.out.println("4(architect )"); String a=String.valueOf(TSUtility.readMenuSelection()); if(a.equals("1")){//No position System.out.println("Current employee position assignment: None"); System.out.println("Please enter the name of the current employee:"); String name=TSUtility.readKeyBoard(4,false); System.out.println("Please enter the age of the current employee:"); int age=TSUtility.readInt(); System.out.println("Please enter the salary of the current employee:"); double salary=TSUtility.readDouble(); Employee employee=new Employee(++count,name,age,salary); employees.add(employee); System.out.println("Personnel added successfully!"); TSUtility.readReturn(); }else if(a.equals("2")){//programmer System.out.println("The current employee's position assignment is: programmer"); System.out.println("Please enter the name of the current employee:"); String name=TSUtility.readKeyBoard(4,false); System.out.println("Please enter the age of the current employee:"); int age=TSUtility.readInt(); System.out.println("Please enter the salary of the current employee:"); double salary=TSUtility.readDouble(); System.out.println("Please configure a good desktop computer for the current employee"); PC pc=new PC().addPC(); Programmer programmer=new Programmer(++count,name,age,salary,pc); employees.add(programmer); TSUtility.readReturn(); }else if(a.equals("3")){//designer System.out.println("Current employee position assignment: Designer"); System.out.println("Please enter the name of the current employee:"); String name=TSUtility.readKeyBoard(4,false); System.out.println("Please enter the age of the current employee:"); int age=TSUtility.readInt(); System.out.println("Please enter the salary of the current employee:"); double salary=TSUtility.readDouble(); System.out.println("Please configure a good laptop for the current Designer:"); NoteBook noteBook=new NoteBook().addNoteBook(); System.out.println("Please enter the current designer's bonus:"); double bonus=TSUtility.readDouble(); Designer designer=new Designer(++count,name,age,salary,noteBook,bonus); employees.add(designer); System.out.println("Personnel added successfully!"); TSUtility.readReturn(); }else {//architect System.out.println("The current employee's position assignment is: Architect"); System.out.println("Please enter the name of the current employee:"); String name=TSUtility.readKeyBoard(4,false); System.out.println("Please enter the age of the current employee:"); int age=TSUtility.readInt(); System.out.println("Please enter the salary of the current employee:"); double salary=TSUtility.readDouble(); System.out.println("Please configure a good printing device for the current Architect:"); Printer printer=new Printer().addPrinter(); System.out.println("Please set the bonus for the current Architect:"); double bonus=TSUtility.readDouble(); System.out.println("Please set the stock of the current Architect:"); Integer stock=TSUtility.readstock(); Architect architect=new Architect(++count,name,age,salary,printer,bonus,stock); employees.add(architect); System.out.println("Personnel added successfully!"); TSUtility.readReturn(); } } //Deletion of employees public void delEmployee(int id) throws TeamException { 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);//Dynamic ID, which changes with the deletion of personnel ID } flag=true; } } if(flag){ System.out.println("Delete succeeded!"); count--; }else { throw new TeamException("The employee does not exist"); } } //Employee view public void showEmployee() throws InterruptedException { TSUtility.loadSpecialEffects(); System.out.println("ID\t full name\t Age\t wages\t position\t state\t bonus\t shares\t Receiving equipment"); for (int i = 0; i < employees.size(); i++) { System.out.println(""+employees.get(i)); } } //Modify employee information (name, age, salary) 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.println("Name("+emp.getName()+"):"); String name=TSUtility.readString(4,emp.getName()); System.out.println("Age("+emp.getAge()+"):"); int age=Integer.parseInt(TSUtility.readString(2,emp.getAge()+"")); System.out.println("Wages("+emp.getSalary()+"):"); double salary=Double.parseDouble(TSUtility.readString(6,emp.getSalary()+"")); emp.setName(name); emp.setAge(age); emp.setSalary(salary); employees.set(i,emp); flag=true; } } if(flag){ System.out.println("Modification succeeded!"); }else { try { throw new TeamException("The employee does not exist"); } catch (TeamException e) { e.printStackTrace(); } } } }
Teamservice for team personnel management:
package service; /* Team management module */ import domain.Architect; import domain.Designer; import domain.Employee; import domain.Programmer; public class TeamService { //Static variable, which is used to automatically generate the unique ID of the team, that is, memberId, for new members of the development team. (tip: the method of increasing 1 should be used) private static int counter = 1; //The maximum number of members of the development team. final is a static constant and variable names are all capitalized private final int MAX_MEMBER = 5; //Array, programmer array Programmer[] team = new Programmer[MAX_MEMBER]; //Actual number of team members private int total = 0; public TeamService() { } public TeamService(int counter, Programmer[] team, int total) { this.counter = counter; this.team = team; this.total = total; } public Programmer[] getTeam() { Programmer[] team = new Programmer[total]; for (int i = 0; i < total; i++) { team[i] = this.team[i]; } return team; } //Initializes the current team member array public void clearTeam() { team = new Programmer[MAX_MEMBER]; counter = 1; total = 0; this.team = team; } //Add team members public void addMember(Employee e) throws TeamException { if (total >= MAX_MEMBER) { throw new TeamException("The member is full and cannot be added"); } if (!(e instanceof Programmer)) { throw new TeamException("The member is not a developer and cannot be added"); } Programmer p = (Programmer) e; if (isExist(p)) { throw new TeamException("The employee is already in the team"); } if (!(p.getStatus())) { throw new TeamException("The employee is already a member of a team"); } //The team requires at most one architect, at most two designers and at most three programmers int numArchitect = 0; int numDesigner = 0; int numProgrammer = 0; for (int i = 0; i < total; i++) { if (team[i] instanceof Architect) { numArchitect++; } else if (team[i] instanceof Designer) { numDesigner++; } else if (team[i] instanceof Programmer) { numProgrammer++; } } if (p instanceof Architect) { if (numArchitect >= 1) { throw new TeamException("There can be at most one architect on the team"); } } else if (p instanceof Designer) { if (numDesigner >= 2) { throw new TeamException("There can be no more than two designers on the team"); } } else if (p instanceof Programmer) { if (numProgrammer >= 3) { throw new TeamException("There can be no more than three programmers on the team"); } } //Add to array p.setStatus(false); p.setMemberId(counter++); team[total++] = p; } //Determine whether this member already exists in the team public boolean isExist(Programmer p) { for (int i = 0; i < total; i++) { if (team[i].getId() == p.getId()) { return true; } } return false; } //Delete the members of the specified memberld (members already in the team) public void removeMember(int memberld) throws TeamException { int n=0; //Find the employee of the specified memberld, delete it, traverse it, and report an exception if it is not found for (; n < total; n++) { if (team[n].getMemberId() == memberld){ team[n].setStatus(true); break; } } if (n == total){ throw new TeamException("The member cannot be found and cannot be deleted"); } for (int i = 0; i < total; i++) { team[i-1]=team[i]; } team[--total]=null; } }
Project development management ProjectService:
package service; /* Project development management module */ import domain.Programmer; import domain.Project; import view.TSUtility; import java.util.ArrayList; import java.util.Random; public class ProjectService { private ArrayList<Project> pro=new ArrayList<>(); private int count=1; //add item public void addProject() throws InterruptedException { System.out.println("Project reference:-------------------------------------"); System.out.println("1.Xiaomi official website: a website similar to Xiaomi official website has been developed web project"); System.out.println("2.Public welfare online mall: Maoning Morning Commonweal mall is China's commonweal online electronic mall."); System.out.println("3.Blog system: Java Blog system, so that everyone with a story can better express their ideas!"); System.out.println("4.Online collaborative document editing system: a very common function, suitable for document editing in the group."); System.out.println("------------------------------------------------------------"); TSUtility.readReturn(); System.out.println("Please enter the serial number of the item you want to add: "); char ch=TSUtility.readMenuSelection(); switch (ch){ case '1': Project p1=new Project(); p1.setProId(count++); p1.setProjectName("Xiaomi official website"); p1.setDesName("The development is similar to Xiaomi's official website web project"); pro.add(p1); TSUtility.loadSpecialEffects(); System.out.println("Items added:"+p1.getProjectName()); break; case '2': Project p2=new Project(); p2.setProId(count++); p2.setProjectName("Public welfare online mall"); p2.setDesName("Maoning Morning Commonweal mall is China's commonweal online electronic mall"); pro.add(p2); TSUtility.loadSpecialEffects(); System.out.println("Items added:"+p2.getProjectName()); break; case '3': Project p3=new Project(); p3.setProId(count++); p3.setProjectName("Blog system"); p3.setDesName("Java Blog system, so that everyone with a story can better express their ideas!"); pro.add(p3); TSUtility.loadSpecialEffects(); System.out.println("Items added:"+p3.getProjectName()); break; case '4': Project p4=new Project(); p4.setProId(count++); p4.setProjectName("Online collaborative document editing system"); p4.setDesName("A very common function, suitable for document editing in the group."); pro.add(p4); TSUtility.loadSpecialEffects(); System.out.println("Items added:"+p4.getProjectName()); break; default: System.out.println("This item does not exist!"); break; } } //Project allocation team development public void dealingPro (Programmer[] team){ System.out.println("The current team members are:"); for (int i = 0; i < team.length; i++) { System.out.println(team[i]); } System.out.println("Please create a team name for the current team:"); String teamName=TSUtility.readKeyBoard(6,false); //Assign items randomly Random r=new Random(); int RandomNum= r.nextInt(pro.size()); Project project=this.pro.get(RandomNum); project.setTeamName(teamName); project.setTeam(team); project.setStatus(true); pro.set(RandomNum,project); } //View the current status of the project public void showPro() throws InterruptedException { TSUtility.loadSpecialEffects(); for (int i = 0; i < pro.size(); i++) { System.out.println(pro.get(i)); } } //Delete selected items 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);//Dynamic ID change } flag=true; } } if (flag){ System.out.println("Delete succeeded!"); count--; }else { try { throw new TeamException("This item does not exist!"); } catch (TeamException e) { e.printStackTrace(); } } } //Traverse all the elements of the collection to get all the data public ArrayList<Project> getAllPro(){ for (int i = 0; i < pro.size(); i++) { System.out.println(pro.get(i)); } return pro; } }
3. view package:
User login / registration interface LoginView:
package view; /* *User login / registration interface */ import java.util.Scanner; @SuppressWarnings("all") public class LoginView { //Initialization value is required, so that the default initialization of String type is not null; private String userName="";//user name private String password="";//Login password //User registration information public void register() throws InterruptedException { TSUtility.loadSpecialEffects(); System.out.println("Start registration..."); Scanner sc = new Scanner(System.in); System.out.println("Please enter the name of the account you want to register (the name is no more than four digits):"); String userName = TSUtility.readKeyBoard(4, false); this.userName=userName; System.out.println("Please enter your login password (no more than eight digits):"); String password = TSUtility.readKeyBoard(8, false); this.password=password; System.out.println("Registration succeeded, please login again."); } //User login public void Login() throws InterruptedException { //Limit number of login failures int count = 5; boolean flag = true; //Cycle of login interface while (flag) { System.out.println("********************🐱"); System.out.println("*** <Login interface> ***"); System.out.println("*** (: ***🐱"); System.out.println("********************🐱"); //Input of account information and login judgment System.out.println("Please enter your account name"); String userName = TSUtility.readKeyBoard(4, false); System.out.println("Please enter your login password"); String password = TSUtility.readKeyBoard(8, false); if (this.userName.length() == 0 || this.password.length() == 0) { System.out.println("Your account information was not detected. Please re-enter or register"); register(); } else if (this.userName.equals(userName) && this.password.equals(password)) { TSUtility.loadSpecialEffects(); System.out.println("Login succeeded, welcome:" + userName); flag = false; } else { count--; if (count <= 0) { System.out.println("Login times is zero, unable to log in, exit."); return; } System.out.println("Login failed, user name mismatch or password error, remaining" + count + "Login opportunities,Please re-enter"); } } } //User modification public void revise() throws InterruptedException { boolean flag = true; //Modify the cycle of the interface while (flag) { System.out.println("********************🐱"); System.out.println("*** <Modify interface> ***"); System.out.println("*** (: ***🐱"); System.out.println("********************🐱"); System.out.println("Please enter the type you need to modify:"); System.out.println("1(Modify user name)"); System.out.println("2(Change password name)"); System.out.println("3(Modify user name and password name)"); System.out.println("4(Do not modify,sign out)"); Scanner sc = new Scanner(System.in); String num = sc.next(); if (num.equals("1")) { System.out.println("Please enter the new account name you need to modify:"); String userName = TSUtility.readKeyBoard(4, false); this.userName = userName; System.out.println("Modification succeeded!"); } else if (num.equals("2")) { System.out.println("Please enter the new account password you need to change:"); String password = TSUtility.readKeyBoard(8, false); this.password = password; System.out.println("Modification succeeded!"); } else if (num.equals("3")) { System.out.println("Please enter the new account name you need to modify:"); String userName = TSUtility.readKeyBoard(4, false); this.userName = userName; System.out.println("Please enter the new password you need to change:"); String password = TSUtility.readKeyBoard(8, false); this.password = password; System.out.println("Modification succeeded!"); } else if (num.equals("4")) { System.out.println("Are you sure you want to quit? Y/N"); char ch = TSUtility.readConfirmSelection(); if (ch == 'Y') { System.out.println("Exiting..."); TSUtility.loadSpecialEffects(); flag = false; } } else { System.out.println("Input error! Please enter "1" or "2" or "3" or "4":"); } } } }
Team modification interface Teamview:
package view; import domain.Employee; import domain.Programmer; import service.NameListService; import service.TeamException; import service.TeamService; import java.util.ArrayList; public class TeamView { private NameListService listSvc=new NameListService(); private TeamService teamSvc=new TeamService(); private ArrayList<Programmer[]> team=new ArrayList<Programmer[]>(); //Team management public void enterMainMenu(){ boolean flag=true; char key='0'; do { if(key != '1'){ listAllEmployees(); } System.out.println("1-Team list 2-Add team member 3-Delete team member 4-Exit, please select(1-4): "); key=TSUtility.readMenuSelection(); System.out.println(); switch (key){ case '1': listTeam(); break; case '2': addMember(); break; case '3': deleteMember(); break; case '4': System.out.println("Are you sure you want to exit? y/n"); char ch=TSUtility.readConfirmSelection(); if(ch == 'Y'){ team.add(teamSvc.getTeam());//Return array teamSvc.clearTeam();//Initializes the current team member array flag=false; } break; default: System.out.println("The information you entered is incorrect, please re-enter!"); break; } }while(flag); } //Show view all team members private void listAllEmployees(){ System.out.println("\\n-------------------------------Develop team scheduling software--------------------------------\\n"); ArrayList<Employee> emps = listSvc.getAllEmployees(); if(emps.size() == 0){ System.out.println("No customer record exists!"); }else { System.out.println("ID\\t full name\\t Age\\t wages\\t position\\t state\\t bonus\\t shares\\t Receiving equipment"); } for (Employee e:emps){ System.out.println(""+e); } System.out.println("-------------------------------------------------------------------------------"); } //Displays a list of development team members private void listTeam(){ System.out.println("\n--------------------Team member list---------------------\n"); Programmer[] team=teamSvc.getTeam(); if (team.length == 0){ System.out.println("The development team currently has no members!"); }else { System.out.println("TID/ID\t full name\t Age\t wages\t position\t bonus\t shares"); } //Enhanced for loop for (Programmer p:team){ System.out.println(" " + p.getDetailsForTeam()); } System.out.println("-----------------------------------------------------"); } //Add members to team private void addMember(){ System.out.println("---------------------Add member---------------------"); System.out.println("Please enter the employee to add ID: "); int id=TSUtility.readInt(); try{ Employee e=listSvc.getEmployee(id); teamSvc.addMember(e); System.out.println("Successfully added!"); } catch (TeamException e) { System.out.println("Adding failed because:"+e.getMessage()); } //Enter to continue TSUtility.readReturn(); } //Delete the person with the specified ID in the team private void deleteMember(){ System.out.println("---------------------Delete member---------------------"); System.out.print("Please enter the name of the employee to delete TID: "); int id=TSUtility.readInt(); System.out.println("Are you sure to delete( y/n)"); char ch=TSUtility.readConfirmSelection(); if(ch == 'n'){ return; } try { teamSvc.removeMember(id); System.out.println("Delete succeeded"); } catch (TeamException e) { System.out.println("Deletion failed, reason:" + e.getMessage()); } // Press enter to continue TSUtility.readReturn(); } // Join the team and get more team public ArrayList<Programmer[]> getManyTeam() { boolean flag = true; char key = 0; do { System.out.println("※※※※※※※※※※※"); System.out.println("※ Team scheduling interface ※"); System.out.println("※※※※※※※※※※※"); System.out.print("1-Add team 2-View team 3-Delete team 4-Exit, please select(1-4): "); key = TSUtility.readMenuSelection(); System.out.println(); switch (key) { case '1': enterMainMenu(); break; case '2': System.out.println("-------Team list--------"); for (Programmer[] team : team) { for (int i = 0; i < team.length; i++) { System.out.println(team[i]); } System.out.println("------------------"); } break; case '3': System.out.println("Please enter the team you want to delete"); int num = TSUtility.readInt(); if (num<=team.size()) { System.out.print("Are you sure you want to delete(Y/N): "); char de = TSUtility.readConfirmSelection(); if (de == 'Y') { team.remove(num-1); }else { System.out.println("Please consider clearly!"); } }else { System.out.println("There is no such team, please input normally!"+"At present, the team has only"+team.size()+"individual"); } break; case '4': System.out.print("Confirm whether to exit(Y/N): "); char yn = TSUtility.readConfirmSelection(); if (yn == 'Y') { flag = false; } break; default: System.out.println("The information you entered is incorrect, please re-enter!"); break; } } while (flag); return team; } }
Final collection display module (main operation interface) IndexView:
package view; import domain.Programmer; import service.NameListService; import service.ProjectService; import service.TeamException; import java.util.ArrayList; /* Run main interface class */ public class IndexView { private final static LoginView loginView = new LoginView(); private final static NameListService nameListService = new NameListService(); private final static TeamView teamView = new TeamView(); private final static ProjectService projectService = new ProjectService(); private ArrayList<Programmer[]> manyTeam = null; public void Menu() { boolean flag = true; char key = '0'; System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣"); System.out.println("🔣 🔣"); System.out.println("🔣 Welcome to the project development team distribution management software 🔣"); System.out.println("🔣 🔣"); System.out.println("🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣"); System.out.println("🐕"); System.out.println("🐕"); System.out.println("🐕"); System.out.println("🐕-----------<Please log in first>-------------🐕"); TSUtility.readReturn(); try { loginView.Login(); } catch (InterruptedException e) { e.printStackTrace(); } do { 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: "); key = TSUtility.readMenuSelectionPro(); switch (key) { case '1': try { loginView.revise(); } catch (InterruptedException e) { e.printStackTrace(); } break; case '2': try { nameListService.showEmployee(); } catch (InterruptedException e) { e.printStackTrace(); } boolean flagSec = true; char keySec = '0'; do { System.out.println("🔣 ~Developer management main menu~ 🔣"); System.out.println("🐕1. <Addition of developers> *"); System.out.println("🐖2. <Developer view> *"); System.out.println("🐱3. <Developer modifications> *"); System.out.println("🐂4. <Developer deletion> *"); System.out.println("🐇5. <Exit the current menu> *"); System.out.println("⬇Please select: "); keySec = TSUtility.readMenuSelectionPro(); switch (keySec) { case '1': nameListService.addEmployee(); break; case '2': try { nameListService.showEmployee(); } catch (InterruptedException e) { e.printStackTrace(); } break; case '3': System.out.println("Please enter the employee to be modified id:"); int j = TSUtility.readInt(); nameListService.modifyEmployee(j); break; case '4': System.out.println("Please enter the employee to delete id:"); int i = TSUtility.readInt(); try { nameListService.delEmployee(i); } catch (TeamException e) { e.printStackTrace(); } break; case '5': System.out.println("Please confirm whether to exit:( Y/N)"); char ch = TSUtility.readConfirmSelection(); if (ch == 'Y') { flagSec = false; } break; default: System.out.println("Input error, please re-enter!"); break; } } while (flagSec); break; case '3': manyTeam = teamView.getManyTeam(); break; case '4': boolean flagThr = true; char keyThr = '0'; do { System.out.println("🔣 ~Development project management main menu~ 🔣"); System.out.println("🐕1. <Addition of items> *"); System.out.println("🐖2. <Project assignment development team> *"); System.out.println("🐱3. <View of items> *"); System.out.println("🐂4. <Deletion of items> *"); System.out.println("🐇5. <Exit the current menu> *"); System.out.println("⬇Please select: "); keyThr = TSUtility.readMenuSelectionPro(); switch (keyThr) { case '1': try { projectService.addProject(); } catch (InterruptedException e) { e.printStackTrace(); } break; case '2': for (Programmer[] pro : manyTeam) { projectService.dealingPro(pro); } break; case '3': try { projectService.showPro(); } catch (InterruptedException e) { e.printStackTrace(); } break; case '4': System.out.println("Please enter the items to be deleted id:"); int j = TSUtility.readInt(); projectService.delPro(j); break; case '5': System.out.print("Confirm whether to exit(Y/N): "); char ch = TSUtility.readConfirmSelection(); if (ch == 'Y') { flagThr = false; } break; default: System.out.println("Incorrect input! Please re-enter!"); break; } } while (flagThr); break; case '5': System.out.print("Confirm whether to exit(Y/N): "); char ch = TSUtility.readConfirmSelection(); if (ch == 'Y') { flag = false; } break; default: break; } } while (flag); } public static void main(String[] args) { new IndexView().Menu(); } }
7, ENDING
The above is the summary of this simple text project. Thank you!!