用Java代码写一个学生学籍管理系统
时间: 2023-03-30 17:03:06 浏览: 139
下面是一份使用 Java 编写的学生学籍管理系统的代码示例:
```
import java.util.ArrayList;
import java.util.Scanner;
public class StudentRecordSystem {
ArrayList<Student> students = new ArrayList<>();
public static void main(String[] args) {
StudentRecordSystem system = new StudentRecordSystem();
system.run();
}
private void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1. 添加学生,2. 查询学生,3. 退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
queryStudent();
break;
case 3:
System.out.println("系统已退出");
return;
default:
System.out.println("输入错误,请重试");
}
}
}
private void addStudent() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生姓名:");
String name = scanner.nextLine();
System.out.println("请输入学生学号:");
String id = scanner.nextLine();
Student student = new Student(name, id);
students.add(student);
System.out.println("学生已添加:" + student);
}
private void queryStudent() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生学号:");
String id = scanner.nextLine();
for (Student student : students) {
if (student.getId().equals(id)) {
System.out.println("学生信息:" + student);
return;
}
}
System.out.println("未找到学生:" + id);
}
}
class Student {
private String name;
private String id;
public Student(String name, String id) {
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
@Override
public String toString() {
return "姓名:" + name + ",学号:" + id;
}
}
```
代码的功能是提供一
阅读全文