Java输出一个学生成绩管理系统
时间: 2023-03-19 16:25:20 浏览: 96
好的,以下是一个简单的 Java 学生成绩管理系统的代码示例:
```java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Student> students = new ArrayList<>();
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. 删除学生信息");
System.out.println("6. 退出");
int choice = input.nextInt();
switch (choice) {
case 1:
addStudent(students, input);
break;
case 2:
displayAllStudents(students);
break;
case 3:
displayStudentInfo(students, input);
break;
case 4:
modifyStudentInfo(students, input);
break;
case 5:
deleteStudent(students, input);
break;
case 6:
System.out.println("谢谢使用!");
return;
default:
System.out.println("无效的操作,请重新选择!");
break;
}
}
}
public static void addStudent(List<Student> students, Scanner input) {
System.out.println("请输入学生姓名:");
String name = input.next();
System.out.println("请输入学生学号:");
String id = input.next();
System.out.println("请输入学生年龄:");
int age = input.nextInt();
System.out.println("请输入学生性别(男/女):");
String gender = input.next();
Student student = new Student(name, id, age, gender);
students.add(student);
System.out.println("添加学生成功!");
}
public static void displayAllStudents(List<Student> students) {
if (students.isEmpty()) {
System.out.println("暂无学生信息!");
return;
}
System.out.println("所有学生信息如下:");
for (Student student : students) {
System.out.println(student.toString());
}
}
public static void displayStudentInfo(List<Student> students, Scanner input) {
if (students.isEmpty()) {
System.out.println("暂无学生信息!");
return;
}
System.out.println("请输入要查看的学生学号:");
String id = input.next();
for (Student student : students) {
if (student.getId().equals(id)) {
System.out.println(student.toString());
return;
}
}
System.out.println("未找到该学生信息!");
}
public static void modifyStudentInfo(List<Student> students, Scanner input) {
if (students.isEmpty()) {
System.out.println("暂无学生信息!");
return;
}
System.out.println("请输入要修改的学生学号:");
String id = input.next();
for (Student student : students) {
if (student.getId().equals(id)) {
System.out.println("请输入学生新姓名:");
String name = input.next();
System.out.println("请输入学生新年龄:");
int age = input.nextInt();
System.out.println("请输入学生新性别(男/女):");
String gender = input.next();
student.setName(name);
student.setAge(age);
student.setGender(gender);
System.out.println("修改学生信息成功
阅读全文