查找一个一个java学生管理系的代码
时间: 2024-02-06 19:11:16 浏览: 51
java代码-使用java解决学生管理系统的问题的源代码
抱歉,我不能提供完整的代码,但我可以给您提供一个简单的学生信息管理系统的代码框架,您可以根据自己的需要进行修改和完善。
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class StudentManagementSystem {
private List<Student> students;
public StudentManagementSystem() {
this.students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void deleteStudent(int index) {
students.remove(index);
}
public void updateStudent(int index, Student student) {
students.set(index, student);
}
public void printAllStudents() {
for (Student student : students) {
System.out.println(student.toString());
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StudentManagementSystem system = new StudentManagementSystem();
while (true) {
System.out.println("1. 添加学生");
System.out.println("2. 删除学生");
System.out.println("3. 修改学生");
System.out.println("4. 查看所有学生");
System.out.println("0. 退出");
System.out.print("请输入操作编号:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
// 添加学生,输入学生信息
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(name, age, gender);
system.addStudent(student);
System.out.println("学生添加成功!");
break;
case 2:
// 删除学生,输入学生编号
System.out.print("请输入要删除的学生编号:");
int index = scanner.nextInt();
system.deleteStudent(index);
System.out.println("学生删除成功!");
break;
case 3:
// 修改学生,输入学生编号和学生信息
System.out.print("请输入要修改的学生编号:");
int index2 = scanner.nextInt();
System.out.print("请输入学生姓名:");
String name2 = scanner.next();
System.out.print("请输入学生年龄:");
int age2 = scanner.nextInt();
System.out.print("请输入学生性别:");
String gender2 = scanner.next();
// 创建学生对象,更新到系统中
Student student2 = new Student(name2, age2, gender2);
system.updateStudent(index2, student2);
System.out.println("学生修改成功!");
break;
case 4:
// 查看所有学生
system.printAllStudents();
break;
case 0:
// 退出程序
System.exit(0);
default:
System.out.println("无效的操作编号,请重新输入!");
}
}
}
}
class Student {
private String name;
private int age;
private String gender;
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
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 String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
@Override
public String toString() {
return "姓名:" + name + "\t年龄:" + age + "\t性别:" + gender;
}
}
```
以上是一个简单的学生信息管理系统的代码框架,其中包括了添加、删除、修改和查看所有学生的功能。您可以根据需要进行修改和完善。
阅读全文