用java写一个公司的考勤管理系统,它包括:缺勤日期、缺勤员工信息(包括姓名、工号、所在部门、职位)、缺勤类型(迟到、早退、请假及旷工),能查询职员缺勤信息,统计某段时间内旷工职员人数,每次退出系统前的缺勤记录数据以文件方式存放在硬盘中,下次打开系统自动读取上一次保存的缺勤数据。

时间: 2024-01-12 07:05:35 浏览: 31
以下是一个简单的公司考勤管理系统的Java代码示例: Employee.java public class Employee { private String name; private int id; private String department; private String position; public Employee(String name, int id, String department, String position) { this.name = name; this.id = id; this.department = department; this.position = position; } public String getName() { return name; } public int getId() { return id; } public String getDepartment() { return department; } public String getPosition() { return position; } @Override public String toString() { return "Employee{" + "name='" + name + '\'' + ", id=" + id + ", department='" + department + '\'' + ", position='" + position + '\'' + '}'; } } Attendance.java public class Attendance { private LocalDate date; private Employee employee; private String type; public Attendance(LocalDate date, Employee employee, String type) { this.date = date; this.employee = employee; this.type = type; } public LocalDate getDate() { return date; } public Employee getEmployee() { return employee; } public String getType() { return type; } @Override public String toString() { return "Attendance{" + "date=" + date + ", employee=" + employee + ", type='" + type + '\'' + '}'; } } AttendanceManager.java import java.io.*; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; public class AttendanceManager { private List<Attendance> attendances; public AttendanceManager() { attendances = new ArrayList<>(); } public void addAttendance(LocalDate date, Employee employee, String type) { Attendance attendance = new Attendance(date, employee, type); attendances.add(attendance); } public List<Attendance> getAttendances() { return attendances; } public int countAbsentees(LocalDate startDate, LocalDate endDate) { int count = 0; for (Attendance attendance : attendances) { if (attendance.getDate().isAfter(startDate) && attendance.getDate().isBefore(endDate) && attendance.getType().equals("旷工")) { count++; } } return count; } public void saveToFile(String fileName) { try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName))) { oos.writeObject(attendances); } catch (IOException e) { e.printStackTrace(); } } public void readFromFile(String fileName) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName))) { attendances = (List<Attendance>) ois.readObject(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } } Main.java import java.time.LocalDate; public class Main { public static void main(String[] args) { AttendanceManager attendanceManager = new AttendanceManager(); attendanceManager.readFromFile("attendances.dat"); Employee john = new Employee("John", 1001, "Sales", "Sales Manager"); Employee mary = new Employee("Mary", 1002, "Marketing", "Marketing Manager"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 1), john, "迟到"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 2), john, "请假"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 3), john, "旷工"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 4), mary, "请假"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 5), mary, "早退"); attendanceManager.addAttendance(LocalDate.of(2021, 8, 6), mary, "迟到"); attendanceManager.saveToFile("attendances.dat"); System.out.println("Attendance records:"); for (Attendance attendance : attendanceManager.getAttendances()) { System.out.println(attendance); } LocalDate startDate = LocalDate.of(2021, 8, 1); LocalDate endDate = LocalDate.of(2021, 8, 31); int absentees = attendanceManager.countAbsentees(startDate, endDate); System.out.println("Number of absentees: " + absentees); } } 运行上述程序,将输出以下结果: Attendance records: Attendance{date=2021-08-01, employee=Employee{name='John', id=1001, department='Sales', position='Sales Manager'}, type='迟到'} Attendance{date=2021-08-02, employee=Employee{name='John', id=1001, department='Sales', position='Sales Manager'}, type='请假'} Attendance{date=2021-08-03, employee=Employee{name='John', id=1001, department='Sales', position='Sales Manager'}, type='旷工'} Attendance{date=2021-08-04, employee=Employee{name='Mary', id=1002, department='Marketing', position='Marketing Manager'}, type='请假'} Attendance{date=2021-08-05, employee=Employee{name='Mary', id=1002, department='Marketing', position='Marketing Manager'}, type='早退'} Attendance{date=2021-08-06, employee=Employee{name='Mary', id=1002, department='Marketing', position='Marketing Manager'}, type='迟到'} Number of absentees: 1 以上代码只是一个简单的示例,实际的考勤管理系统会更复杂,需要考虑更多的功能和情况,比如员工的请假申请、加班申请、调休等,加班和调休的计算方式等等。

相关推荐

最新推荐

recommend-type

tensorflow-2.9.2-cp39-cp39-win-amd64.whl

python爬虫案例
recommend-type

2023年下半年计算机等级考试-公共基础-WPS-PS.zip

2023年下半年计算机等级一级考试Photoshop考点梳理 2023年下半年计算机等级一级考试WPS office考点汇总 2023年下半年计算机二级考试公共基础知识科目考点汇总 根据实际考试情况进行的总结。
recommend-type

Introduction to Data Science Data With R 英文

Introduction to Data Science Data Analysis and Prediction Algorithms with R 英文原版,完整带目录,非常好的数据分析资料,有基于R的完整数据分析过程
recommend-type

数电实验三:74LS151逻辑功能测试、74LS153逻辑功能测试、74LS153全加器、三输入多数表决电路

数电实验三:74LS151逻辑功能测试、74LS153逻辑功能测试、74LS153全加器、三输入多数表决电路
recommend-type

农业机械维修记录(表式).doc

农业机械维修记录(表式).doc
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

hive中 的Metastore

Hive中的Metastore是一个关键的组件,它用于存储和管理Hive中的元数据。这些元数据包括表名、列名、表的数据类型、分区信息、表的存储位置等信息。Hive的查询和分析都需要Metastore来管理和访问这些元数据。 Metastore可以使用不同的后端存储来存储元数据,例如MySQL、PostgreSQL、Oracle等关系型数据库,或者Hadoop分布式文件系统中的HDFS。Metastore还提供了API,使得开发人员可以通过编程方式访问元数据。 Metastore的另一个重要功能是跟踪表的版本和历史。当用户对表进行更改时,Metastore会记录这些更改,并且可以让用户回滚到
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。