基于JavaBean的学生请假销假管理系统代码
时间: 2023-09-09 22:06:35 浏览: 118
好的,以下是一个基于JavaBean的学生请假销假管理系统的代码示例:
1. 学生类(Student.java)
```java
public class Student {
private int id;
private String name;
private String className;
// 构造函数
public Student(int id, String name, String className) {
this.id = id;
this.name = name;
this.className = className;
}
// getter和setter
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 String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}
```
2. 请假类(Leave.java)
```java
public class Leave {
private int id;
private int studentId;
private String startTime;
private String endTime;
private String reason;
private String status;
// 构造函数
public Leave(int id, int studentId, String startTime, String endTime, String reason, String status) {
this.id = id;
this.studentId = studentId;
this.startTime = startTime;
this.endTime = endTime;
this.reason = reason;
this.status = status;
}
// getter和setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
```
3. 审批类(Approval.java)
```java
public class Approval {
private int id;
private int leaveId;
private int approverId;
private String approveTime;
private String result;
// 构造函数
public Approval(int id, int leaveId, int approverId, String approveTime, String result) {
this.id = id;
this.leaveId = leaveId;
this.approverId = approverId;
this.approveTime = approveTime;
this.result = result;
}
// getter和setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getLeaveId() {
return leaveId;
}
public void setLeaveId(int leaveId) {
this.leaveId = leaveId;
}
public int getApproverId() {
return approverId;
}
public void setApproverId(int approverId) {
this.approverId = approverId;
}
public String getApproveTime() {
return approveTime;
}
public void setApproveTime(String approveTime) {
this.approveTime = approveTime;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
```
4. 主函数(Main.java)
```java
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
students.add(new Student(1, "张三", "高一一班"));
students.add(new Student(2, "李四", "高一一班"));
students.add(new Student(3, "王五", "高一二班"));
ArrayList<Leave> leaves = new ArrayList<>();
leaves.add(new Leave(1, 1, "2021-10-01", "2021-10-03", "家里有事", "待审批"));
leaves.add(new Leave(2, 2, "2021-10-02", "2021-10-04", "生病了", "待审批"));
leaves.add(new Leave(3, 3, "2021-10-03", "2021-10-05", "去旅游", "待审批"));
ArrayList<Approval> approvals = new ArrayList<>();
// 学生提交请假申请
for (Leave leave : leaves) {
System.out.println("学生 " + students.get(leave.getStudentId() - 1).getName()
+ " 提交了请假申请,开始时间:" + leave.getStartTime() + ",结束时间:" + leave.getEndTime());
// 审批人审批请假申请
if (leave.getStatus().equals("待审批")) {
System.out.println("请假申请待审批...");
for (int i = 1; i <= 3; i++) {
if (i != leave.getStudentId()) {
approvals.add(new Approval(approvals.size() + 1, leave.getId(), i, "2021-10-01", ""));
System.out.println("审批人 " + i + " 已审批,请假申请状态:" + leave.getStatus());
if (leave.getStatus().equals("已批准")) {
break;
}
}
}
}
// 学生销假
if (leave.getStatus().equals("已批准")) {
System.out.println("学生 " + students.get(leave.getStudentId() - 1).getName()
+ " 已请假成功,开始时间:" + leave.getStartTime() + ",结束时间:" + leave.getEndTime());
leave.setStatus("已销假");
System.out.println("学生 " + students.get(leave.getStudentId() - 1).getName()
+ " 已销假成功,开始时间:" + leave.getStartTime() + ",结束时间:" + leave.getEndTime());
}
}
}
}
```
上述代码实现了学生请假销假管理系统的基本功能,包括学生提交请假申请、审批人审批请假申请、学生销假等操作。您可以根据实际需求进行修改和优化。
阅读全文