对的,请编写,实现学生信息的录入、查询、修改、删除等功能的完整的系统
时间: 2024-02-29 17:54:24 浏览: 27
好的,以下是一个简单的学生信息管理系统的Java实现,包含了学生信息的录入、查询、修改、删除等功能。请注意,这只是一个基本的示例程序,实际开发中还需要考虑更多细节和实现方式。
```java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
// 学生类
static class Student {
String id; // 学号
String name; // 姓名
int age; // 年龄
String gender; // 性别
public Student(String id, String name, int age, String gender) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
}
public String toString() {
return "学号:" + this.id + ",姓名:" + this.name + ",年龄:" + this.age + ",性别:" + this.gender;
}
}
// 学生列表
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("0. 退出");
// 读取用户输入
int choice = scanner.nextInt();
// 根据用户选择执行相应的操作
switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
queryStudent(scanner);
break;
case 3:
modifyStudent(scanner);
break;
case 4:
deleteStudent(scanner);
break;
case 0:
System.exit(0);
default:
System.out.println("输入有误,请重新输入!");
}
}
}
// 添加学生信息
public static void addStudent(Scanner scanner) {
// 读取学生信息
System.out.println("请输入学生信息:");
System.out.print("学号:");
String id = scanner.next();
System.out.print("姓名:");
String name = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
System.out.print("性别:");
String gender = scanner.next();
// 创建学生对象并添加到列表中
Student student = new Student(id, name, age, gender);
studentList.add(student);
System.out.println("添加成功!");
}
// 查询学生信息
public static void queryStudent(Scanner scanner) {
// 读取学生学号
System.out.print("请输入学生学号:");
String id = scanner.next();
// 查找学生并输出信息
boolean found = false;
for (Student student : studentList) {
if (student.id.equals(id)) {
System.out.println(student);
found = true;
}
}
if (!found) {
System.out.println("未找到该学生!");
}
}
// 修改学生信息
public static void modifyStudent(Scanner scanner) {
// 读取学生学号
System.out.print("请输入学生学号:");
String id = scanner.next();
// 查找学生并修改信息
boolean found = false;
for (Student student : studentList) {
if (student.id.equals(id)) {
System.out.println("请输入修改后的学生信息:");
System.out.print("姓名:");
String name = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
System.out.print("性别:");
String gender = scanner.next();
student.name = name;
student.age = age;
student.gender = gender;
System.out.println("修改成功!");
found = true;
}
}
if (!found) {
System.out.println("未找到该学生!");
}
}
// 删除学生信息
public static void deleteStudent(Scanner scanner) {
// 读取学生学号
System.out.print("请输入学生学号:");
String id = scanner.next();
// 查找学生并删除信息
boolean found = false;
for (Student student : studentList) {
if (student.id.equals(id)) {
studentList.remove(student);
System.out.println("删除成功!");
found = true;
break;
}
}
if (!found) {
System.out.println("未找到该学生!");
}
}
}
```
相关推荐
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)