运用java,写一个公司考勤系统,能够实现录入修改查询职员的缺勤记录,统计职员的旷工记录
时间: 2024-06-11 07:07:06 浏览: 164
由于题目较为简单,且缺乏细节,因此只提供一个基本的代码框架,供参考:
```java
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class AttendanceSystem {
private Map<String, Integer> absentCounts; // 记录职员缺勤天数,key为职员姓名,value为缺勤天数
public AttendanceSystem() {
this.absentCounts = new HashMap<>();
}
// 录入职员缺勤记录
public void addAbsentRecord(String name, int count) {
if (absentCounts.containsKey(name)) {
int currentCount = absentCounts.get(name);
absentCounts.put(name, currentCount + count);
} else {
absentCounts.put(name, count);
}
}
// 修改职员缺勤记录
public void modifyAbsentRecord(String name, int count) {
if (absentCounts.containsKey(name)) {
absentCounts.put(name, count);
} else {
System.out.println("职员不存在!");
}
}
// 查询职员缺勤记录
public int queryAbsentRecord(String name) {
if (absentCounts.containsKey(name)) {
return absentCounts.get(name);
} else {
System.out.println("职员不存在!");
return -1;
}
}
// 统计职员旷工记录
public int countAbsenteeism(String name) {
if (absentCounts.containsKey(name)) {
int count = absentCounts.get(name);
if (count >= 7) {
return count - 6; // 超过6天算旷工
} else {
return 0;
}
} else {
System.out.println("职员不存在!");
return -1;
}
}
// 测试代码
public static void main(String[] args) {
AttendanceSystem system = new AttendanceSystem();
// 添加职员缺勤记录
system.addAbsentRecord("张三", 3);
system.addAbsentRecord("李四", 5);
system.addAbsentRecord("王五", 7);
// 修改职员缺勤记录
system.modifyAbsentRecord("李四", 4);
// 查询职员缺勤记录
System.out.println(system.queryAbsentRecord("张三"));
System.out.println(system.queryAbsentRecord("李四"));
System.out.println(system.queryAbsentRecord("王五"));
System.out.println(system.queryAbsentRecord("赵六"));
// 统计职员旷工记录
System.out.println(system.countAbsenteeism("张三"));
System.out.println(system.countAbsenteeism("李四"));
System.out.println(system.countAbsenteeism("王五"));
System.out.println(system.countAbsenteeism("赵六"));
}
}
```
阅读全文