写一个学生管理系统的代码,用java实现
时间: 2023-03-13 16:52:10 浏览: 44
java代码-使用java解决学生管理系统的问题的源代码
好的,这是一个简单的学生管理系统代码实现,使用 Java 语言:
```
import java.util.Scanner;
class Student {
private String name;
private int age;
private int score;
public Student(String name, int age, int score) {
this.name = name;
this.age = age;
this.score = score;
}
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 int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
public class StudentManager {
private static final int MAX_STUDENT_COUNT = 100;
private static Student[] students = new Student[MAX_STUDENT_COUNT];
private static int studentCount = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1. 添加学生 2. 查询学生 3. 退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
queryStudent();
break;
case 3:
System.exit(0);
default:
System.out.println("输入有误,请重新输入");
}
}
}
private static void addStudent(Scanner scanner) {
if (studentCount >= MAX_STUDENT_COUNT) {
System.out.println("学生人数已达到上限,无法添加");
return;
}
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生年龄:");
int age = scanner.nextInt();
System.out.println("请输入学生分数:");
int score = scanner.nextInt();
Student student = new Student(name, age, score);
students[studentCount++] = student;
System.out.println("添加成功");
}
private static void queryStudent() {
System.out.println("姓名\t年龄\t分数");
for
阅读全文