学生请假管理系统简单代码JAVA
时间: 2023-08-25 10:06:18 浏览: 61
以下是一个简单的学生请假管理系统的代码示例,使用Java语言编写,采用了基本的面向对象编程思想:
```java
import java.util.ArrayList;
class Student {
private String name;
private int id;
private int absences;
private ArrayList<String> excuses;
public Student(String name, int id) {
this.name = name;
this.id = id;
this.absences = 0;
this.excuses = new ArrayList<>();
}
public void addExcuse(String excuse) {
this.excuses.add(excuse);
}
public ArrayList<String> getExcuses() {
return this.excuses;
}
public void addAbsence() {
this.absences++;
}
public int getAbsences() {
return this.absences;
}
public String getName() {
return this.name;
}
public int getId() {
return this.id;
}
}
class AttendanceSystem {
private ArrayList<Student> students;
public AttendanceSystem() {
this.students = new ArrayList<>();
}
public void addStudent(Student student) {
this.students.add(student);
}
public Student getStudent(int id) {
for (Student student : this.students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
public void markAbsence(int id) {
Student student = getStudent(id);
if (student != null) {
student.addAbsence();
}
}
public void addExcuse(int id, String excuse) {
Student student = getStudent(id);
if (student != null) {
student.addExcuse(excuse);
}
}
public String getStudentReport(int id) {
Student student = getStudent(id);
if (student != null) {
String report = "Student Name: " + student.getName() + "\nStudent ID: " + student.getId() + "\nAbsences: " + student.getAbsences() + "\nExcuses: " + student.getExcuses() + "\n";
return report;
}
return null;
}
}
```
以上代码定义了两个类:`Student`和`AttendanceSystem`。`Student`类代表一个学生,包含了学生的姓名、学号、缺勤次数和请假记录;`AttendanceSystem`类代表整个请假管理系统,包含了所有学生的信息和管理操作。
使用这个代码示例,你可以创建学生对象并添加到请假管理系统中,记录学生的缺勤次数和请假记录,以及查询某个学生的请假报告。你可以根据自己的需求进行修改和扩展。