用java编写一个学生成绩管理系统.列出某个学生的所有成绩,列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分分区段统计某门课程的学生总评成绩学生
时间: 2024-02-12 16:02:24 浏览: 75
用java写的一个简单的学生成绩管理系统(含代码).doc
好的,我可以为您提供一些思路和代码示例。
首先,我们需要定义学生和课程两个类,以及成绩管理系统的主类。具体代码如下所示:
```java
//学生类
public class Student {
private String name; //姓名
private int id; //学号
private HashMap<String, Integer> scores; //成绩列表,键为科目名,值为成绩
public Student(String name, int id) {
this.name = name;
this.id = id;
scores = new HashMap<>();
}
public void addScore(String subject, int score) {
scores.put(subject, score);
}
public int getScore(String subject) {
return scores.get(subject);
}
public String getName() {
return name;
}
public int getId() {
return id;
}
}
//课程类
public class Course {
private String name; //课程名称
private ArrayList<Student> students; //学生列表
public Course(String name) {
this.name = name;
students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public ArrayList<Student> getStudents() {
return students;
}
public String getName() {
return name;
}
}
//成绩管理系统类
public class ScoreManager {
private ArrayList<Student> students; //学生列表
private ArrayList<Course> courses; //课程列表
public ScoreManager() {
students = new ArrayList<>();
courses = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void addCourse(Course course) {
courses.add(course);
}
public void showStudentScores(Student student) {
System.out.println(student.getName() + "的成绩:");
for (String subject : student.getScores().keySet()) {
System.out.println(subject + ": " + student.getScore(subject));
}
}
public void showCourseScores(Course course) {
System.out.println(course.getName() + "的成绩:");
for (Student student : course.getStudents()) {
int totalScore = 0;
for (String subject : student.getScores().keySet()) {
totalScore += student.getScore(subject);
}
System.out.println(student.getName() + ": " + totalScore);
}
}
public void showScoreDistribution(Course course) {
System.out.println(course.getName() + "的成绩分布:");
int[] scoreCounts = new int[5]; //存储各分数段人数的数组
for (Student student : course.getStudents()) {
int totalScore = 0;
for (String subject : student.getScores().keySet()) {
totalScore += student.getScore(subject);
}
if (totalScore >= 90) {
scoreCounts[0]++;
} else if (totalScore >= 80) {
scoreCounts[1]++;
} else if (totalScore >= 70) {
scoreCounts[2]++;
} else if (totalScore >= 60) {
scoreCounts[3]++;
} else {
scoreCounts[4]++;
}
}
System.out.println("90分以上:" + scoreCounts[0] + "人");
System.out.println("80-89分:" + scoreCounts[1] + "人");
System.out.println("70-79分:" + scoreCounts[2] + "人");
System.out.println("60-69分:" + scoreCounts[3] + "人");
System.out.println("60分以下:" + scoreCounts[4] + "人");
}
}
```
接下来,我们可以在主函数中创建一些学生和课程对象,并添加成绩信息。代码示例如下:
```java
public static void main(String[] args) {
//创建学生对象
Student s1 = new Student("张三", 1001);
s1.addScore("语文", 85);
s1.addScore("数学", 92);
s1.addScore("英语", 78);
Student s2 = new Student("李四", 1002);
s2.addScore("语文", 78);
s2.addScore("数学", 90);
s2.addScore("英语", 85);
Student s3 = new Student("王五", 1003);
s3.addScore("语文", 92);
s3.addScore("数学", 86);
s3.addScore("英语", 90);
//创建课程对象
Course c1 = new Course("语文");
c1.addStudent(s1);
c1.addStudent(s2);
c1.addStudent(s3);
Course c2 = new Course("数学");
c2.addStudent(s1);
c2.addStudent(s2);
c2.addStudent(s3);
Course c3 = new Course("英语");
c3.addStudent(s1);
c3.addStudent(s2);
c3.addStudent(s3);
//创建成绩管理系统对象
ScoreManager manager = new ScoreManager();
manager.addStudent(s1);
manager.addStudent(s2);
manager.addStudent(s3);
manager.addCourse(c1);
manager.addCourse(c2);
manager.addCourse(c3);
//列出某个学生的所有成绩
manager.showStudentScores(s1);
//列出某门课程每个学生的总评成绩
manager.showCourseScores(c1);
//统计某门课程的学生总评成绩学生总评成绩的总评分分区段
manager.showScoreDistribution(c1);
}
```
运行上述代码,就可以得到输出结果了。当然,这只是一个简单的示例,实际应用中还需要考虑很多其他因素,比如成绩的输入和修改、成绩的排序和排名等等。
阅读全文