帮我写java学生信息管理系统
时间: 2023-07-10 17:11:58 浏览: 61
好的,我可以给您提供一个简单的 Java 学生信息管理系统的代码框架,您可以根据您的需求进行修改和完善。以下是代码:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
private static ArrayList<Student> studentList = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:");
System.out.println("1.添加学生信息");
System.out.println("2.删除学生信息");
System.out.println("3.修改学生信息");
System.out.println("4.查询学生信息");
System.out.println("5.退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
deleteStudent(scanner);
break;
case 3:
updateStudent(scanner);
break;
case 4:
queryStudent(scanner);
break;
case 5:
System.out.println("感谢使用学生信息管理系统,再见!");
System.exit(0);
break;
default:
System.out.println("请输入正确的操作序号!");
break;
}
}
}
private static void addStudent(Scanner scanner) {
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生学号:");
String id = scanner.next();
System.out.println("请输入学生性别:");
String gender = scanner.next();
System.out.println("请输入学生年龄:");
int age = scanner.nextInt();
Student student = new Student(name, id, gender, age);
studentList.add(student);
System.out.println("添加学生信息成功!");
}
private static void deleteStudent(Scanner scanner) {
System.out.println("请输入要删除的学生学号:");
String id = scanner.next();
boolean isDelete = false;
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
studentList.remove(i);
isDelete = true;
break;
}
}
if (isDelete) {
System.out.println("删除学生信息成功!");
} else {
System.out.println("未找到该学生信息!");
}
}
private static void updateStudent(Scanner scanner) {
System.out.println("请输入要修改的学生学号:");
String id = scanner.next();
boolean isUpdate = false;
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生性别:");
String gender = scanner.next();
System.out.println("请输入学生年龄:");
int age = scanner.nextInt();
Student student = new Student(name, id, gender, age);
studentList.set(i, student);
isUpdate = true;
break;
}
}
if (isUpdate) {
System.out.println("修改学生信息成功!");
} else {
System.out.println("未找到该学生信息!");
}
}
private static void queryStudent(Scanner scanner) {
System.out.println("请输入要查询的学生学号:");
String id = scanner.next();
boolean isQuery = false;
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
System.out.println(studentList.get(i));
isQuery = true;
break;
}
}
if (!isQuery) {
System.out.println("未找到该学生信息!");
}
}
}
class Student {
private String name;
private String id;
private String gender;
private int age;
public Student(String name, String id, String gender, int age) {
this.name = name;
this.id = id;
this.gender = gender;
this.age = age;
}
@Override
public String toString() {
return "学生姓名:" + name + "\n学生学号:" + id + "\n学生性别:" + gender + "\n学生年龄:" + age;
}
public String getId() {
return id;
}
}
```
该系统包括了添加、删除、修改和查询学生信息的功能,您可以根据需要进行修改和完善。
阅读全文