java学生管理系统源代码
时间: 2023-10-02 08:10:17 浏览: 47
抱歉,我无法提供完整的学生管理系统源代码。然而,以下是一个简单的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 displayAllStudents() {
for(Student student : students) {
System.out.println(student);
}
}
public void displayStudentByID(int id) {
for(Student student : students) {
if(student.getID() == id) {
System.out.println(student);
}
}
}
public void displayStudentsByGPA(double gpa) {
for(Student student : students) {
if(student.getGPA() >= gpa) {
System.out.println(student);
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StudentManagementSystem system = new StudentManagementSystem();
while(true) {
System.out.println("1. Add a Student");
System.out.println("2. Remove a Student");
System.out.println("3. Display All Students");
System.out.println("4. Display Student by ID");
System.out.println("5. Display Students by GPA");
System.out.println("6. Exit");
int choice = scanner.nextInt();
switch(choice) {
case 1:
System.out.print("Enter Student ID: ");
int id = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter Student Name: ");
String name = scanner.nextLine();
System.out.print("Enter Student GPA: ");
double gpa = scanner.nextDouble();
system.addStudent(new Student(id, name, gpa));
break;
case 2:
System.out.print("Enter Student ID: ");
id = scanner.nextInt();
scanner.nextLine();
system.removeStudent(new Student(id, "", 0.0));
break;
case 3:
system.displayAllStudents();
break;
case 4:
System.out.print("Enter Student ID: ");
id = scanner.nextInt();
scanner.nextLine();
system.displayStudentByID(id);
break;
case 5:
System.out.print("Enter Minimum GPA: ");
gpa = scanner.nextDouble();
system.displayStudentsByGPA(gpa);
break;
case 6:
System.exit(0);
default:
System.out.println("Invalid Choice!");
}
}
}
}
class Student {
private int id;
private String name;
private double gpa;
public Student(int id, String name, double gpa) {
this.id = id;
this.name = name;
this.gpa = gpa;
}
public int getID() {
return id;
}
public String getName() {
return name;
}
public double getGPA() {
return gpa;
}
public String toString() {
return id + " " + name + " " + gpa;
}
}
```
这是一个非常基本的Java学生管理系统,它通过控制台输入和输出来与用户交互。你可以根据自己的需求进行修改和改进。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)