用Java语言写一个学生管理系统
时间: 2023-03-15 15:08:29 浏览: 88
要写一个学生管理系统,需要先定义一个学生类,包括学生的姓名、年龄、学号等信息。然后可以提供一些方法来操作学生信息,如添加、删除、修改、查询学生信息等。
实现这个学生管理系统,可以使用 Java 语言,如下是一个示例:
```
import java.util.ArrayList;
import java.util.List;
public class Student {
private String name;
private int age;
private String studentId;
public Student(String name, int age, String studentId) {
this.name = name;
this.age = age;
this.studentId = studentId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
}
public class StudentManager {
private List<Student> students;
public StudentManager() {
students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void deleteStudent(String studentId) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getStudentId().equals(studentId)) {
students.remove(i);
break;
}
}
}
public void updateStudent(Student student) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getStudentId().equals(student.getStudentId())) {
students.set(i, student);
break;
}
}
}
public Student findStudent(String studentId) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getStudentId().equals(studentId)) {
return students.get(i);
}
}
return null;
}
}
```
在上面的示例代码中,`Student` 类表示学生信息,包含
阅读全文