用Java代码实现班级学生成绩管理系统 完成学生信息管理。具体包括学生信息的新增、修改、删除、查询等功能。学生信息包括学号、姓名、性别、年龄等; 2、完成课程信息管理。具体包括课程编号、课程名称、课时数、课程性质(选修、必修)、学分、授课教师等; 3、完成学生成绩管理。具体针对选择的课程对学生的成绩进行录入;并能实现单个学生单门课程的成绩录入过程;同时完成成绩的查找功能
时间: 2023-07-10 07:41:38 浏览: 79
好的,以下是一个基本的班级学生成绩管理系统的Java代码示例,包括学生信息管理、课程信息管理和学生成绩管理功能。具体实现细节可以根据实际需求进行修改。
```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class StudentScoreManagementSystem {
// 定义学生类
static class Student {
String id; // 学号
String name; // 姓名
String gender; // 性别
int age; // 年龄
Map<String, Integer> scores; // 成绩
public Student(String id, String name, String gender, int age) {
this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.scores = new HashMap<>();
}
public void addScore(String courseId, int score) {
scores.put(courseId, score);
}
public int getScore(String courseId) {
return scores.getOrDefault(courseId, -1);
}
public void printInfo() {
System.out.println("学号:" + id + ",姓名:" + name + ",性别:" + gender + ",年龄:" + age);
System.out.println("成绩:");
for (String courseId : scores.keySet()) {
System.out.println(courseId + ":" + scores.get(courseId));
}
System.out.println();
}
}
// 定义课程类
static class Course {
String id; // 课程编号
String name; // 课程名称
int hours; // 课时数
String type; // 课程性质
int credit; // 学分
String teacher; // 授课教师
public Course(String id, String name, int hours, String type, int credit, String teacher) {
this.id = id;
this.name = name;
this.hours = hours;
this.type = type;
this.credit = credit;
this.teacher = teacher;
}
public void printInfo() {
System.out.println("课程编号:" + id + ",课程名称:" + name + ",课时数:" + hours + ",课程性质:" + type + ",学分:" + credit + ",授课教师:" + teacher);
}
}
// 学生列表
static List<Student> students = new ArrayList<>();
// 课程列表
static List<Course> courses = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1-学生信息管理,2-课程信息管理,3-学生成绩管理,4-退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
studentManagement(scanner);
break;
case 2:
courseManagement(scanner);
break;
case 3:
scoreManagement(scanner);
break;
case 4:
System.out.println("程序已退出!");
return;
default:
System.out.println("无效操作!");
}
}
}
// 学生信息管理
public static void studentManagement(Scanner scanner) {
while (true) {
System.out.println("请选择操作:1-新增学生,2-修改学生,3-删除学生,4-查询学生,5-返回上一级");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent(scanner);
break;
case 2:
modifyStudent(scanner);
break;
case 3:
deleteStudent(scanner);
break;
case 4:
queryStudent(scanner);
break;
case 5:
return;
default:
System.out.println("无效操作!");
}
}
}
// 新增学生
public static void addStudent(Scanner scanner) {
System.out.println("请输入学生信息:");
System.out.print("学号:");
String id = scanner.next();
System.out.print("姓名:");
String name = scanner.next();
System.out.print("性别:");
String gender = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
Student student = new Student(id, name, gender, age);
students.add(student);
System.out.println("添加成功!");
}
// 修改学生
public static void modifyStudent(Scanner scanner) {
System.out.print("请输入要修改的学生学号:");
String id = scanner.next();
Student student = findStudentById(id);
if (student == null) {
System.out.println("学号为 " + id + " 的学生不存在!");
return;
}
System.out.println("请输入新的学生信息:");
System.out.print("姓名:");
String name = scanner.next();
System.out.print("性别:");
String gender = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
student.name = name;
student.gender = gender;
student.age = age;
System.out.println("修改成功!");
}
// 删除学生
public static void deleteStudent(Scanner scanner) {
System.out.print("请输入要删除的学生学号:");
String id = scanner.next();
Student student = findStudentById(id);
if (student == null) {
System.out.println("学号为 " + id + " 的学生不存在!");
return;
}
students.remove(student);
System.out.println("删除成功!");
}
// 查询学生
public static void queryStudent(Scanner scanner) {
System.out.print("请输入要查询的学生学号:");
String id = scanner.next();
Student student = findStudentById(id);
if (student == null) {
System.out.println("学号为 " + id + " 的学生不存在!");
return;
}
student.printInfo();
}
// 根据学号查找学生
public static Student findStudentById(String id) {
for (Student student : students) {
if (student.id.equals(id)) {
return student;
}
}
return null;
}
// 课程信息管理
public static void courseManagement(Scanner scanner) {
while (true) {
System.out.println("请选择操作:1-新增课程,2-修改课程,3-删除课程,4-查询课程,5-返回上一级");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addCourse(scanner);
break;
case 2:
modifyCourse(scanner);
break;
case 3:
deleteCourse(scanner);
break;
case 4:
queryCourse(scanner);
break;
case 5:
return;
default:
System.out.println("无效操作!");
}
}
}
// 新增课程
public static void addCourse(Scanner scanner) {
System.out.println("请输入课程信息:");
System.out.print("课程编号:");
String id = scanner.next();
System.out.print("课程名称:");
String name = scanner.next();
System.out.print("课时数:");
int hours = scanner.nextInt();
System.out.print("课程性质:");
String type = scanner.next();
System.out.print("学分:");
int credit = scanner.nextInt();
System.out.print("授课教师:");
String teacher = scanner.next();
Course course = new Course(id, name, hours, type, credit, teacher);
courses.add(course);
System.out.println("添加成功!");
}
// 修改课程
public static void modifyCourse(Scanner scanner) {
System.out.print("请输入要修改的课程编号:");
String id = scanner.next();
Course course = findCourseById(id);
if (course == null) {
System.out.println("课程编号为 " + id + " 的课程不存在!");
return;
}
System.out.println("请输入新的课程信息:");
System.out.print("课程名称:");
String name = scanner.next();
System.out.print("课时数:");
int hours = scanner.nextInt();
System.out.print("课程性质:");
String type = scanner.next();
System.out.print("学分:");
int credit = scanner.nextInt();
System.out.print("授课教师:");
String teacher = scanner.next();
course.name = name;
course.hours = hours;
course.type = type;
course.credit = credit;
course.teacher = teacher;
System.out.println("修改成功!");
}
// 删除课程
public static void deleteCourse(Scanner scanner) {
System.out.print("请输入要删除的课程编号:");
String id = scanner.next();
Course course = findCourseById(id);
if (course == null) {
System.out.println("课程编号为 " + id + " 的课程不存在!");
return;
}
courses.remove(course);
System.out.println("删除成功!");
}
// 查询课程
public static void queryCourse(Scanner scanner) {
System.out.print("请输入要查询的课程编号:");
String id = scanner.next();
Course course = findCourseById(id);
if (course == null) {
System.out.println("课程编号为 " + id + " 的课程不存在!");
return;
}
course.printInfo();
}
// 根据课程编号查找课程
public static Course findCourseById(String id) {
for (Course course : courses) {
if (course.id.equals(id)) {
return course;
}
}
return null;
}
// 学生成绩管理
public static void scoreManagement(Scanner scanner) {
while (true) {
System.out.println("请选择操作:1-录入成绩,2-查询成绩,3-返回上一级");
int choice = scanner.nextInt();
switch (choice) {
case 1:
inputScore(scanner);
break;
case 2:
queryScore(scanner);
break;
case 3:
return;
default:
System.out.println("无效操作!");
}
}
}
// 录入成绩
public static void inputScore(Scanner scanner) {
System.out.print("请输入要录入成绩的学生学号:");
String id = scanner.next();
Student student = findStudentById(id);
if (student == null) {
System.out.println("学号为 " + id + " 的学生不存在!");
return;
}
System.out.println("请输入要录入成绩的课程编号:");
String courseId = scanner.next();
Course course = findCourseById(courseId);
if (course == null) {
System.out.println("课程编号为 " + courseId + " 的课程不存在!");
return;
}
System.out.println("请输入成绩:");
int score = scanner.nextInt();
student.addScore(courseId, score);
System.out.println("成绩录入成功!");
}
// 查询成绩
public static void queryScore(Scanner scanner) {
System.out.print("请输入要查询成绩的学生学号:");
String id = scanner.next();
Student student = findStudentById(id);
if (student == null) {
System.out.println("学号为 " + id + " 的学生不存在!");
return;
}
System.out.println("请输入要查询成绩的课程编号:");
String courseId = scanner.next();
int score = student.getScore(courseId);
if (score == -1) {
System.out.println("学号为 " + id + " 的学生在课程编号为 " + courseId + " 的课程中没有成绩!");
return;
}
System.out.println("学号为 " + id + " 的学生在课程编号为 " + courseId + " 的课程中的成绩为:" + score);
}
}
```
阅读全文