用Java语言写一个学生成绩管理系统项目
时间: 2023-12-06 16:02:45 浏览: 90
java语言课程设计学生成绩管理系统项目源码.zip
5星 · 资源好评率100%
好的,我可以为您提供一份基本的Java学生成绩管理系统项目的代码模板,您可以在此基础上进行修改和扩展。
首先,我们需要定义一个`Student`类来表示学生,包括学生姓名、学号和成绩等属性。代码如下:
```java
public class Student {
private String name;
private String id;
private int score;
public Student(String name, String id, int score) {
this.name = name;
this.id = id;
this.score = score;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
```
然后,我们定义一个`StudentManagementSystem`类来管理学生信息,包括添加学生、删除学生、修改学生信息和查询学生信息等功能。代码如下:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class StudentManagementSystem {
private List<Student> students = new ArrayList<>();
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(String id) {
Student student = findStudent(id);
if (student != null) {
students.remove(student);
} else {
System.out.println("学号为" + id + "的学生不存在!");
}
}
public void updateStudent(String id, int score) {
Student student = findStudent(id);
if (student != null) {
student.setScore(score);
} else {
System.out.println("学号为" + id + "的学生不存在!");
}
}
public void queryStudent(String id) {
Student student = findStudent(id);
if (student != null) {
System.out.println("学生姓名:" + student.getName() + ",学号:" + student.getId() + ",成绩:" + student.getScore());
} else {
System.out.println("学号为" + id + "的学生不存在!");
}
}
private Student findStudent(String id) {
for (Student student : students) {
if (student.getId().equals(id)) {
return student;
}
}
return null;
}
public void start() {
Scanner scanner = new Scanner(System.in);
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. 退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("请输入学生姓名:");
String name = scanner.next();
System.out.print("请输入学生学号:");
String id = scanner.next();
System.out.print("请输入学生成绩:");
int score = scanner.nextInt();
Student student = new Student(name, id, score);
addStudent(student);
System.out.println("添加成功!");
break;
case 2:
System.out.print("请输入要删除的学生学号:");
id = scanner.next();
removeStudent(id);
break;
case 3:
System.out.print("请输入要修改信息的学生学号:");
id = scanner.next();
System.out.print("请输入新的成绩:");
score = scanner.nextInt();
updateStudent(id, score);
break;
case 4:
System.out.print("请输入要查询信息的学生学号:");
id = scanner.next();
queryStudent(id);
break;
case 5:
System.out.println("退出系统!");
System.exit(0);
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
public static void main(String[] args) {
StudentManagementSystem system = new StudentManagementSystem();
system.start();
}
}
```
以上就是一个简单的Java学生成绩管理系统项目的代码模板。您可以根据需要进行修改和扩展。
阅读全文