在开始动手前先进行需求分析和模型设计。
需求分析:
先看看我们所需要的系统功能结构:
这个项目简单来说需要完成用户、开发人员、开发团队和开发项目的增删改查,在完成相应的功能之后还要与用户交互实现即设计好交互界面,能够让用户访问新项目内容,使用相关功能。
系统流程如下:
•
模拟实现一个基于文本界面的
《
项目开发团队分配管理软件
》
•
熟悉
Java
面向对象的高级特性,进一步掌握编程技巧和调试技巧
•
主要涉及以下知识点:
①
类的继承性和多态性
②
对象的值传递、接口
③
static
和
final
修饰符
④
特殊类的使用:包装类、抽象类、内部类
⑤
异常处理
⑥
Java
基本语法和流程控制
⑦
数组,
ArrayList
集合
三大模块之间的联系如下:
①
com.team.view
模块为主控模块,负责菜单的显示和处理用户操作
②
com.team.service
模块为实体对象(
Employee
及其子类如程序员等)的管理模块,
NameListService
和
TeamService
类分别用各自的数组来管理公司员工和开发团队成员对象
③
ProjectService
是对项目的操作对象类
④
domain
模块为
Employee
及其子类等
JavaBean
类所在的包
梳理完毕之后开始分模块进行设计和代码实现:
先准备好八个实体类和一个接口:
七个实体类分别是:员工、程序员、设计师、架构师、电脑、打印机、型号类、项目类;
还有一个接口,
实现类实现接口的方法,返回各自属性的信息。
如图所示:
结构如下:
每个类的代码如下,写法大同小异,个别类存在继承关系:
先写要实现的结构以及接口内的方法:
接口代码如下:
package com.team.domain;
//接口
public interface Equipment {
String getDescription();
}
之后是employee员工类:
package com.team.domain;
//员工类
public class Employee {
private int id;
private String name;
private int age;
private double salary;
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;
}
//实现接口,返回属性信息;
@Override
public String toString() {
return id + "\t" + name + "\t" + age + "\t\t" + salary;
}
}
程序员类是员工类的子类,他们存在继承关系,程序员属于员工类型的一种。
package com.team.domain;
//程序员类
public class Programmer extends Employee {
private int memberId;
private boolean status=true;//人员的状态初始化为true,添加到团队之后为false;
private Equipment equipment;//成员设备
public Programmer(){}
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 boolean isStatus(){return status;}
public void setStatus(boolean status) {
this.status = status;
}
public Equipment getEquipment() {
return equipment;
}
}
设计师类继承程序员类:
package com.team.domain;
//设计师类
public class Designer extends Programmer {
private double 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;
}
}
架构师类同理:
package com.team.domain;
//架构师类
public class Architect extends Designer {
private int stock;//公司奖励的股票;
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;
}
}
之后是以上实体所领用的设备类:
首先是电脑类:电脑类包含设备信息(电脑的型号和显示器)并实现接口返回设备信息。
package com.team.domain;
//电脑类
public class PC implements Equipment {
private String model;//电脑型号
private String display;//显示器
public PC(){}
public PC(String model, String display) {
this.model = model;
this.display = display;
}
@Override
public String getDescription() {
return model + "(" + display + ")";
}
}
打印机类同理:
package com.team.domain;
//打印机类
public class Print implements Equipment {
private String name;//机器名称
private String type;//类型
public Print(){}
public Print(String name, String type) {
this.name = name;
this.type = type;
}
@Override
public String getDescription() {
return name+ "(" +type+ ")" ;
}
}
还有一个型号类:
package com.team.domain;
public class NoteBook implements Equipment {
private String model;//机器型号
private double price;//价格
public NoteBook(){}
public NoteBook(String model, double price) {
this.model = model;
this.price = price;
}
@Override
public String getDescription() {
return model + "(" + price + ")";
}
}
项目类:包含项目的编号、名称、开发团队、开发团队名称以及开发状态这几个属性
package com.team.domain;
import java.util.Arrays;
//项目类
public class Project {
private int proId;//项目号
private String projectName;//项目名称
private String desName;//项目描述
private Programmer[] team;//开发团队
private String teamName;//开发团队名称
private boolean status;//开发状态(true为开发中,false为未开发中)
public Project(int proId, String projectName, Programmer[] team, String teamName,String desName, 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 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;
}
@Override
public String toString() {
return "项目{" +
"项目号=" + proId +
", 项目名称='" + projectName + '\'' +
", 开发团队=" + Arrays.toString(team) +
", 开发团队名称='" + teamName + '\'' +
", 开发状态=" + status +
'}';
}
}
这样八个实体类和一个接口就搞定了,domain模块完成!

实体和接口准备完毕之后可以进行各个功能的实现了!