说明文档
程序员文章站
2022-04-13 08:48:34
...
公司人员招聘信息系统说明
一、主要功能(做了什么?)
本系统主要是实现了人员招聘中的常见功能,包括有:
- 查询员工信息
- 添加员工信息
- 删除员工信息
- 修改员工信息
二、设计了哪些类
2.1 实体类
- Employee 员工类
- Programer 编程人员
- Designer 设计师
- Architect 建造师
2.2 系统相关功能类
- Data类(存储初始化员工的数据)
public static final String[][] EMPLOYEES = {
{"10", "1", "马云", "22", "3000"},
{"13", "2", "马化腾", "32", "18000"},
{"11", "3", "李彦宏", "23", "7000"},
{"11", "4", "刘强东", "24", "7300"},
{"12", "5", "雷军", "28", "10000"},
{"11", "6", "任志强", "22", "6800"},
{"12", "7", "柳传志", "29", "10800"},
{"13", "8", "杨元庆", "30", "19800"},
{"12", "9", "史玉柱", "26", "9800"},
{"11", "10", "丁磊", "21", "6600"},
{"11", "11", "张朝阳", "25", "7100"},
{"12", "12", "杨致远", "27", "9600"}
};
- NameListService 类(对数据进行增删改查持久化操作进行封装)
备注:通过对象的序列化和反序列化将对象存储在文件中来实现数据的持久化操作
序列化和反序列化代码:NameListService -> writeData()
**
* 将List集合写入data.txt
* 序列化操作
*/
public void writeData(){
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("data.txt"));
oos.writeObject(employees);
} catch (IOException e) {
e.printStackTrace();
}
}
**
* 将data.txt中的内容读取到List集合
* 反序列化操作
*/
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data.txt"));
List<Employee> employees = (List<Employee>) ois.readObject();
for (Employee employee : employees) {
System.out.println(employee.toString());
}
return employees;
} catch(Exception e) {
e.printStackTrace();
}
- TeamException 类(自定义一个异常处理异常信息)
- TSUtility 类(工具类,对一些复杂的操作提供统一封装)
三、核心功能与实现
3.1 核心功能
根据用户选择的操作,对数据实现增删改查相关操作,并通过对象的序列化和反序列化将对象存储在文件中来实现数据的持久化操作
3.2 核心代码实现
- 增加员工
public void addEmployee(Employee employee) throws TeamException {
for (int i = 0; i < employees.size(); i++) {
if (employee.getId() == employees.get(i).getId()) {
String msg = "输入的ID已存在";
throw new TeamException(msg);
} else {
continue;
}
}
employees.add(employee);
// 写入文件
writeData();
}
- 删除员工
public void deleteEmployee(int id) throws TeamException
for (int i = 0; i < employees.size(); i++) {
if (id == employees.get(i).getId()) {
employees.remove(i);
break;
} else {
continue;
}
}
if(id >employees.size()||id<0){
String msg = "输入的ID不存在";
throw new TeamException(msg);
}
// 写入文件
writeData();
}
- 修改员工
public void updateEmployee(Employee employee) throws TeamException{
int id = employee.getId();
for (int i = 0; i < employees.size(); i++) {
if (id == employees.get(i).getId()) {
employees.set(i,employee);
break;
} else {
continue;
}
}
if(id >employees.size()||id<0){
String msg = "输入的ID不存在";
throw new TeamException(msg);
}
// 写入文件
writeData();
}
- 查询员工
public void queryEmployee(int id) throws TeamException{
for (int i = 0; i < employees.size(); i++) {
if (id == employees.get(i).getId()) {
System.out.println(employees.get(i).toString());
break;
} else {
continue;
}
}
if(id >employees.size()||id<0){
String msg = "输入的ID不存在";
throw new TeamException(msg);
}
}
四、主入口文件
通过View 类中的main方法实现整个程序的运行