学生管理系统<数组版> 书写一个学生管理系统,要求: 1、创建学生类,包含:属性:String name, int age 等 (方法不做要求) 2、创建一个20个空间的学生类型数组,用来存储学生对象 3、实现学生组数的:增、删、改、查、退出等操作。
时间: 2025-06-21 11:28:08 浏览: 11
学生管理系统(数组版本)可以按照以下步骤设计:
首先,我们需要定义一个简单的学生类,名为`Student`,它将包含姓名(name)和年龄(age)两个属性:
```java
public class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
// getter 和 setter 方法省略(如果需要的话)
}
```
接下来,我们创建一个大小固定的`Student[] studentsArray`,用于存储学生对象:
```java
private static final int ARRAY_SIZE = 20;
Student[] studentsArray = new Student[ARRAY_SIZE];
int currentIndex = 0; // 记录当前学生位置
// 添加学生到数组中(如果还有剩余空间)
public void addStudent(Student student) {
if (currentIndex < ARRAY_SIZE) {
studentsArray[currentIndex++] = student;
} else {
System.out.println("学生数组已满,无法添加更多学生。");
}
}
// 删除学生
public boolean removeStudent(String name) {
for (int i = 0; i < currentIndex; i++) {
if (studentsArray[i].getName().equals(name)) {
// 移除并更新索引
ArrayUtils.swap(studentsArray, i, currentIndex - 1);
currentIndex--;
return true;
}
}
return false; // 找不到对应的学生
}
// 修改学生信息
public void updateStudent(String oldName, String newName, int newAge) {
for (int i = 0; i < currentIndex; i++) {
if (studentsArray[i].getName().equals(oldName)) {
studentsArray[i].setName(newName);
studentsArray[i].setAge(newAge);
return;
}
}
System.out.println("找不到需要修改的学生。");
}
// 查找学生
public Student findStudent(String name) {
for (Student student : studentsArray) {
if (student.getName().equals(name)) {
return student;
}
}
return null; // 如果没找到,则返回null
}
// 退出功能(这里只是一个简单示例,实际应用可能需要更复杂的逻辑处理)
public void exit() {
// 清空数组或其他资源释放操作
studentsArray = new Student[ARRAY_SIZE]; // 或者直接设置为初始状态
currentIndex = 0;
}
```
请注意,上述代码使用了一个假设存在的`ArrayUtils.swap`函数来辅助移除元素,这在真实的项目中通常需要自定义或使用现有的库来提供。
阅读全文
相关推荐





<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="check_logstate.jsp"></jsp:include>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="zh_CN">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎使用后台管理系统</title>
<script type="text/javascript" src="asset/page/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="asset/page/js/bootstrap.min.js"></script>
</head>
<body>
学生请假列表
学生用户
宿舍
开始时间
结束时间
原因
状态
操作
<c:forEach items="${outList}" var="out">
${out.realname}
${out.roomsname}
${out.starttime}
${out.endtime}
${out.reason}
${out.stats}
<c:if test="${out.stats eq '待审批' }">
处理 </c:if>删除
</c:forEach>
${html }
</body>
</html>
学生用户不显示姓名















