Home > Java > javaTutorial > How to use Java to write a simple student leave approval result query system?

How to use Java to write a simple student leave approval result query system?

WBOY
Release: 2023-11-02 14:45:22
Original
1327 people have browsed it

How to use Java to write a simple student leave approval result query system?

How to use Java to write a simple student leave approval result query system?

With the development of education, students asking for leave has become an indispensable part of every school management. In order to facilitate school administrators and students to understand the leave situation, this article will introduce how to use Java to write a simple student leave approval result query system.

First, we need to create a student class (Student), which contains attributes such as the student's name, student number, date of leave, reason for leave, and status of leave. You can use the following code to create a student class:

public class Student {
    private String name; // 学生姓名
    private int id; // 学号
    private String leaveDate; // 请假日期
    private String leaveReason; // 请假事由
    private String leaveStatus; // 请假状态

    // 构造函数
    public Student(String name, int id, String leaveDate, String leaveReason, String leaveStatus) {
        this.name = name;
        this.id = id;
        this.leaveDate = leaveDate;
        this.leaveReason = leaveReason;
        this.leaveStatus = leaveStatus;
    }

    // getter和setter方法
    // ...
}
Copy after login

Next, we need to create a leave management system class (LeaveManagementSystem) to manage students' leave information. You can use the following code to create a leave management system class:

import java.util.ArrayList;
import java.util.List;

public class LeaveManagementSystem {
    private List<Student> studentList; // 学生列表

    public LeaveManagementSystem() {
        studentList = new ArrayList<>();
    }

    // 添加学生请假信息
    public void addStudentLeave(Student student) {
        studentList.add(student);
    }

    // 根据学号查询学生请假信息
    public Student searchStudentLeave(int id) {
        for (Student student : studentList) {
            if (student.getId() == id) {
                return student;
            }
        }
        return null;
    }

    // 查询所有学生请假信息
    public List<Student> getAllStudentLeave() {
        return studentList;
    }
}
Copy after login

In the main function, we can create a LeaveManagementSystem object and perform corresponding operations. The following is a simple example:

public class Main {
    public static void main(String[] args) {
        LeaveManagementSystem system = new LeaveManagementSystem();

        // 添加学生请假信息
        system.addStudentLeave(new Student("张三", 1001, "2021-05-01", "生病", "已批准"));
        system.addStudentLeave(new Student("李四", 1002, "2021-05-02", "参加比赛", "已批准"));

        // 根据学号查询学生请假信息
        Student student = system.searchStudentLeave(1001);
        if (student != null) {
            System.out.println("学生姓名:" + student.getName());
            System.out.println("学号:" + student.getId());
            System.out.println("请假日期:" + student.getLeaveDate());
            System.out.println("请假事由:" + student.getLeaveReason());
            System.out.println("请假状态:" + student.getLeaveStatus());
        }

        // 查询所有学生请假信息
        List<Student> studentList = system.getAllStudentLeave();
        for (Student s : studentList) {
            System.out.println("学生姓名:" + s.getName());
            System.out.println("学号:" + s.getId());
            System.out.println("请假日期:" + s.getLeaveDate());
            System.out.println("请假事由:" + s.getLeaveReason());
            System.out.println("请假状态:" + s.getLeaveStatus());
        }
    }
}
Copy after login

Through the above code, we have implemented a simple student leave approval result query system. Users can add students' leave information, query the leave information of specific students based on their student numbers, or view the leave information of all students.

Of course, this is just a simple example, and the actual leave management system may require more functions and verifications. But through this simple example, we can understand how to use Java to write a student leave approval result query system, and it can be expanded and optimized according to the actual situation.

The above is the detailed content of How to use Java to write a simple student leave approval result query system?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template