企业营销网站建设费用预算/网站建设方案及报价
文章目录
- 前言
- 一、项目要求
- 1.总体要求
- 2.添加团队成员
- 3.删除团队成员
- 4.团队列表
- 二、软件结构设计
- 1.整体设计思路
- 2.com.atguigu.team.domain模块设计
- 2.1 Equipment接口及其各实现子类的设计
- 2.2 Employee类及其各子类的设计
- 3.com.atguigu.team.service模块设计
- 3.1 NameListService类的设计
- 3.2 TeamService类的设计
- 4.实现view包中类
- 总结
前言
模拟实现一个基于文本界面的《开发团队调度软件》
熟悉Java面向对象的高级特性,进一步掌握编程技巧和调试技巧
一、项目要求
1.总体要求
本软件采用单级菜单方式工作。当软件运行时,主界面显示公司成员的列表,如下:
2.添加团队成员
当选择“添加团队成员”菜单时,将执行从列表中添加指定(通过ID)成员到开发团队的功能:
如果添加操作因某种原因失败,将显示类似以下信息(失败原因视具体原因而不同):
失败信息包含以下几种:
成员已满,无法添加
该成员不是开发人员,无法添加
该员工已在本开发团队中
该员工已是某团队成员
该员正在休假,无法添加
团队中至多只能有一名架构师
团队中至多只能有两名设计师
团队中至多只能有三名程序员
3.删除团队成员
当选择“删除团队成员”菜单时,将执行从开发团队中删除指定(通过TeamID)成员的功能:
删除成功后,按回车键将重新显示主界面。
4.团队列表
当选择“团队列表”菜单时,将列出开发团队中的现有成员,例如:
二、软件结构设计
1.整体设计思路
该软件由以下三个模块组成:
com.atguigu.team.view模块为主控模块,负责菜单的显示和处理用户操作
com.atguigu.team.service模块为实体对象(Employee及其子类如程序员等)的管理模块, NameListService和TeamService类分别用各自的数组来管理公司员工和开发团队成员对象
domain模块为Employee及其子类等JavaBean类所在的包
2.com.atguigu.team.domain模块设计
com.atguigu.team.domain模块中包含了所有实体类:
2.1 Equipment接口及其各实现子类的设计
package com.atguigu.team.domain;public interface Equipment {public abstract String getDescription();}
package com.atguigu.team.domain;public class PC implements Equipment {private String model;// 机器型号private String display;// 显示器名称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;}@Overridepublic String getDescription() {return model + "(" + display + ")";}}
package com.atguigu.team.domain;public class Notebook implements Equipment {private String model;//机器型号private double 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() {super();}public Notebook(String model, double price) {super();this.model = model;this.price = price;}@Overridepublic String getDescription() {return model + "(" + price + ")";}}
package com.atguigu.team.domain;public class Printer implements Equipment {private String name;// 机器型号private String 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() {super();}public Printer(String name, String type) {super();this.name = name;this.type = type;}@Overridepublic String getDescription() {return name + "(" + type + ")";}}
2.2 Employee类及其各子类的设计
package com.atguigu.team.domain;public class Employee {private int id;private String name;private int age;private double 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;}public Employee() {super();}public Employee(int id, String name, int age, double salary) {super();this.id = id;this.name = name;this.age = age;this.salary = salary;}}
package com.atguigu.team.domain;import com.atguigu.team.service.Status;public class Programmer extends Employee {private int memberId;// 团队中的IDprivate Status status;// 状态private Equipment equipment;public Programmer() {super();}public Programmer(int id, String name, int age, double salary, Equipment equipment) {super(id, name, age, salary);this.equipment = equipment;}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 getEquipment() {return equipment;}public void setEquipment(Equipment equipment) {this.equipment = equipment;}}
package com.atguigu.team.domain;public class Designer extends Programmer {private double bonus;// 奖金public Designer() {super();}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;}}
package com.atguigu.team.domain;public class Architect extends Designer {private int stock;// 股票public Architect() {super();}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;}}
3.com.atguigu.team.service模块设计
功能:关于开发团队成员的管理:添加、删除等。
说明:
counter为静态变量,用来为开发团队新增成员自动生成团队中的唯一ID,即memberId。(提示:应使用增1的方式)
MAX_MEMBER:表示开发团队最大成员数
team数组:用来保存当前团队中的各成员对象
total:记录团队成员的实际人数
getTeam()方法:返回当前团队的所有对象
返回:包含所有成员对象的数组,数组大小与成员人数一致
addMember(e: Employee)方法:向团队中添加成员
参数:待添加成员的对象
异常:添加失败, TeamException中包含了失败原因
removeMember(memberId: int)方法:从团队中删除成员
参数:待删除成员的memberId
异常:找不到指定memberId的员工,删除失败
3.1 NameListService类的设计
功能:负责将Data中的数据封装到Employee[]数组中,同时提供相关操作Employee[]的方法。
package com.atguigu.team.service;import com.atguigu.team.domain.Architect;
import com.atguigu.team.domain.Designer;
import com.atguigu.team.domain.Employee;
import com.atguigu.team.domain.Equipment;
import com.atguigu.team.domain.Notebook;
import com.atguigu.team.domain.PC;
import com.atguigu.team.domain.Printer;
import com.atguigu.team.domain.Programmer;import static com.atguigu.team.service.Data.*;/*** * @Description 负责将Data中的数据封装在Employee[]数组中,同时提供相关操作Employee[]的方法* @author SCU_zhangxiao Email:zhangx6512@163.com* @version v1.0* @date 2021年5月14日上午8:50:29**/
public class NameListService {private Employee[] employees;/*** 给employees及数组元素进行初始化*/public NameListService() {employees = new Employee[EMPLOYEES.length];for (int i = 0; i < employees.length; i++) {// 获取通用的属性int type = Integer.parseInt(EMPLOYEES[i][0]);int id = Integer.parseInt(EMPLOYEES[i][1]);String name = EMPLOYEES[i][2];int age = Integer.parseInt(EMPLOYEES[i][3]);double salary = Double.parseDouble(EMPLOYEES[i][4]);//Equipment eq;double bonus;int stock;switch (type) {case EMPLOYEE:employees[i] = new Employee(id, name, age, salary);break;case PROGRAMMER:eq = createEquipment(i);employees[i] = new Programmer(id, name, age, salary, eq);break;case DESIGNER:eq = createEquipment(i);bonus = Integer.parseInt(EMPLOYEES[i][5]);employees[i] = new Designer(id, name, age, salary, eq, bonus);break;case ARCHITECT:eq = createEquipment(i);bonus = Integer.parseInt(EMPLOYEES[i][5]);stock = Integer.parseInt(EMPLOYEES[i][6]);employees[i] = new Architect(id, name, age, salary, eq, bonus,stock);break;}}}/***
* @Description 获取指定index位置上的员工的设备
* @author SCU_zhangxiao
* @date 2021年5月14日上午9:29:10
* @param index
* @return*/private Equipment createEquipment(int index) {int type = Integer.parseInt(EQUIPMENTS[index][0]);switch (type) {case PC:return new PC(EQUIPMENTS[index][1], EQUIPMENTS[index][2]);case NOTEBOOK:int price = Integer.parseInt(EQUIPMENTS[index][2]);return new Notebook(EQUIPMENTS[index][1], price);case PRINTER:return new Printer(EQUIPMENTS[index][1], EQUIPMENTS[index][2]);}return null;}/*** * @Description 获取当前所有的员工* @author SCU_zhangxiao* @date 2021年5月21日下午3:15:33* @return*/public Employee[] getAllEmployees() {return employees;}/*** * @Description 获取指定ID的员工对象* @author SCU_zhangxiao* @date 2021年5月21日下午3:54:34* @param id* @return*/public Employee getEmployee(int id) throws TeamException{for(int i = 0;i < employees.length;i++){if(employees[i].getId()==id){return employees[i];}}throw new TeamException("找不到指定的员工");}}
3.2 TeamService类的设计
功能:关于开发团队成员的管理:添加、删除等。
package com.atguigu.team.service;import com.atguigu.team.domain.Architect;
import com.atguigu.team.domain.Designer;
import com.atguigu.team.domain.Employee;
import com.atguigu.team.domain.Programmer;/***
* @Description 关于开发团队成员的管理:添加、删除等
* @author SCU_zhangxiao Email:zhangx6512@163.com
* @version
* @date 2021年5月21日下午4:31:04
**/
public class TeamService {private static int counter = 1;private final int MAX_MEMBER = 5;private Programmer[] team = new Programmer[MAX_MEMBER];private int total;public TeamService(){super();}/*** * @Description 获取开发团队中的所有成员* @author SCU_zhangxiao* @date 2021年5月21日下午4:46:20* @return*/public Programmer[] getTeam(){Programmer[] team = new Programmer[total];for(int i = 0;i <team.length;i++){team[i] = this.team[i];}return team;}/*** * @Description 将指定的员工添加到开发团队中* @author SCU_zhangxiao* @date 2021年5月21日下午5:04:39* @param e*/public void addMember(Employee e) throws TeamException{if(total >= MAX_MEMBER){throw new TeamException("成员已满,无法添加");}if(!(e instanceof Programmer)){throw new TeamException("该成员不是开发人员,无法添加");}if(isExist(e)){throw new TeamException("该员工已在本开发团队中");}Programmer p = (Programmer)e;if("BUSY".equals(p.getStatus().getNAME())){throw new TeamException("该员工已是某团队成员");}else if("VOCATION".equalsIgnoreCase(p.getStatus().getNAME())){throw new TeamException("该员工正在休假,无法添加");}int numOfArch = 0,numOfDes = 0,numOfPro = 0;for(int i = 0;i < total;i++){if(team[i] instanceof Architect){numOfArch++;}else if(team[i] instanceof Designer){numOfDes++;}else if(team[i] instanceof Programmer){numOfPro++;}}if(p instanceof Architect){if(numOfArch >= 1){throw new TeamException("团队中至多只能有一名架构师");}else if(p instanceof Designer){if(numOfDes >= 2){throw new TeamException("团队中至多只能有两名设计师");}}else if(p instanceof Programmer){if(numOfPro >= 3){throw new TeamException("团队中至多只能有三名程序员");}}}//将p添加到现有的team中team[total++] = p;//p的属性赋值p.setStatus(Status.BUSY);p.setMemberId(counter++);}/*** * @Description 判断指定的员工是否已经存在于现有的开发团队中* @author SCU_zhangxiao* @date 2021年5月25日上午10:04:00* @param e* @return*/private boolean isExist(Employee e){// TODO Auto-generated method stubfor(int i = 0;i<total;i++){if(team[i].getId()==e.getId()){return true;}}return false;}public void removeMember(int memberId){}}
4.实现view包中类
package com.atguigu.team.view;import com.atguigu.team.domain.*;
import com.atguigu.team.service.*;public class TeamView {private NameListService listSvc = new NameListService();private TeamService teamSvc = new TeamService();public void enterMainMenu() {boolean loopFlag = true;char key = 0;do {if (key != '1') {listAllEmployees();}System.out.print("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(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.print("确认是否退出(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'Y')loopFlag = false;break;}} while (loopFlag);}// 显示所有的员工成员private void listAllEmployees() {System.out.println("\n-------------------------------开发团队调度软件--------------------------------\n");Employee[] emps = listSvc.getAllEmployees();if (emps.length == 0) {System.out.println("没有客户记录!");} else {System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备");}for (Employee e : emps) {System.out.println(" " + e);}System.out.println("-------------------------------------------------------------------------------");}// 显示开发团队成员列表private void listTeam() {System.out.println("\n--------------------团队成员列表---------------------\n");Programmer[] team = teamSvc.getTeam();if (team.length == 0) {System.out.println("开发团队目前没有成员!");} else {System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票");}for (Programmer p : team) {System.out.println(" " + p.getDetailsForTeam());}System.out.println("-----------------------------------------------------");}// 添加成员到团队private void addMember() {System.out.println("---------------------添加成员---------------------");System.out.print("请输入要添加的员工ID:");int id = TSUtility.readInt();try {Employee e = listSvc.getEmployee(id);teamSvc.addMember(e);System.out.println("添加成功");} catch (TeamException e) {System.out.println("添加失败,原因:" + e.getMessage());}// 按回车键继续...TSUtility.readReturn();}// 从团队中删除指定id的成员private void deleteMember() {System.out.println("---------------------删除成员---------------------");System.out.print("请输入要删除员工的TID:");int id = TSUtility.readInt();System.out.print("确认是否删除(Y/N):");char yn = TSUtility.readConfirmSelection();if (yn == 'N')return;teamSvc.removeMember(id);System.out.println("删除成功");// 按回车键继续...TSUtility.readReturn();}public static void main(String[] args) {TeamView view = new TeamView();view.enterMainMenu();}
}
总结
本文基于Java编程,介绍了“开发团队调度系统”的设计,实现团队员工的增加、删除、显示等功能。