生成一段java的学生管理系统
时间: 2023-10-02 16:11:26 浏览: 68
好的,以下是一个简单的Java学生管理系统的代码,可供参考:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
private ArrayList<Student> students;
public StudentManagementSystem() {
students = new ArrayList<Student>();
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(Student student) {
students.remove(student);
}
public void printAllStudents() {
for (int i = 0; i < students.size(); i++) {
System.out.println(students.get(i));
}
}
public void searchStudentByName(String name) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getName().equalsIgnoreCase(name)) {
System.out.println(students.get(i));
}
}
}
public void updateStudent(Student student) {
System.out.println("Please enter the new information: ");
Scanner input = new Scanner(System.in);
System.out.print("Name: ");
String name = input.nextLine();
System.out.print("Age: ");
int age = input.nextInt();
System.out.print("Email: ");
input.nextLine();
String email = input.nextLine();
student.setName(name);
student.setAge(age);
student.setEmail(email);
}
}
class Student {
private String name;
private int age;
private String email;
public Student(String name, int age, String email) {
this.name = name;
this.age = age;
this.email = email;
}
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 getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String toString() {
return "Name: " + name + ", Age: " + age + ", Email: " + email;
}
}
```
希望这个代码能够帮到你。有什么其它问题吗?
阅读全文