用Java编写一个学生成绩管理系统。学生的属性包括学号、姓名、年龄等。每个学生要学习若干课程,每门课程有平时成绩、其中考试成绩、实习成绩、期末考试成绩以及总评成绩等多个成绩,其中平时成绩的数目不定(因为不同课程的教师布置的平时作业不同),而总评成绩是其它成绩的平均值。请先设计合理的类存放这些信息,然后设计程序完成以下功能: (1)列出某个学生的所有成绩; (2)列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分; (3)分区段统计某门课程的学生总评成绩,例如60分以下的学生人数、60至70分的学生人数等。

时间: 2024-02-09 08:09:59 浏览: 19
好的,下面是我为您提供的Java代码: ``` import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class StudentGradeManagementSystem { public static void main(String[] args) { Scanner input = new Scanner(System.in); List<Student> students = new ArrayList<>(); // 存储学生信息 List<Course> courses = new ArrayList<>(); // 存储课程信息 // 添加学生信息 System.out.print("请输入学生数:"); int numStudents = input.nextInt(); for (int i = 0; i < numStudents; i++) { System.out.print("请输入第" + (i+1) + "个学生的信息:"); System.out.print("学号:"); String id = input.next(); System.out.print("姓名:"); String name = input.next(); System.out.print("年龄:"); int age = input.nextInt(); students.add(new Student(id, name, age)); } // 添加课程信息 System.out.print("请输入课程数:"); int numCourses = input.nextInt(); for (int i = 0; i < numCourses; i++) { System.out.print("请输入第" + (i+1) + "门课程的信息:"); System.out.print("课程名称:"); String name = input.next(); System.out.print("平时成绩占比(例如0.3表示30%):"); double dailyScoreWeight = input.nextDouble(); System.out.print("其中考试成绩占比:"); double examScoreWeight = input.nextDouble(); System.out.print("实习成绩占比:"); double practiceScoreWeight = input.nextDouble(); System.out.print("期末考试成绩占比:"); double finalScoreWeight = input.nextDouble(); courses.add(new Course(name, dailyScoreWeight, examScoreWeight, practiceScoreWeight, finalScoreWeight)); } // 输入每个学生的课程成绩 for (Student student : students) { System.out.print("请输入学生" + student.getName() + "的各科成绩:"); for (Course course : courses) { System.out.print(course.getName() + "的平时成绩数目:"); int numDailyScore = input.nextInt(); List<Double> dailyScores = new ArrayList<>(); for (int i = 0; i < numDailyScore; i++) { System.out.print("第" + (i+1) + "个平时成绩:"); dailyScores.add(input.nextDouble()); } System.out.print(course.getName() + "的其中考试成绩:"); double examScore = input.nextDouble(); System.out.print(course.getName() + "的实习成绩:"); double practiceScore = input.nextDouble(); System.out.print(course.getName() + "的期末考试成绩:"); double finalScore = input.nextDouble(); student.addCourseScore(course, dailyScores, examScore, practiceScore, finalScore); } } // 列出某个学生的所有成绩 System.out.print("请输入要查询成绩的学生姓名:"); String name = input.next(); for (Student student : students) { if (student.getName().equals(name)) { System.out.println(student); } } // 列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分 System.out.print("请输入要查询总评成绩的课程名称:"); String courseName = input.next(); Course course = null; for (Course c : courses) { if (c.getName().equals(courseName)) { course = c; break; } } if (course == null) { System.out.println("未找到该课程!"); return; } double totalScore = 0; int numStudentsWithScore = 0; for (Student student : students) { double score = student.getScore(course); if (score != -1) { System.out.println(student.getName() + "的" + course.getName() + "总评成绩为:" + score); totalScore += score; numStudentsWithScore++; } } double averageScore = totalScore / numStudentsWithScore; System.out.println("所有学生的" + course.getName() + "总评成绩的总评分为:" + averageScore); // 分区段统计某门课程的学生总评成绩 System.out.print("请输入要查询的课程名称:"); courseName = input.next(); course = null; for (Course c : courses) { if (c.getName().equals(courseName)) { course = c; break; } } if (course == null) { System.out.println("未找到该课程!"); return; } System.out.print("请输入分数段的个数:"); int numSections = input.nextInt(); double[] sectionScores = new double[numSections+1]; sectionScores[0] = 0; // 分数段的下限 sectionScores[numSections] = 100; // 分数段的上限 for (int i = 1; i < numSections; i++) { System.out.print("请输入第" + i + "个分数段的下限:"); sectionScores[i] = input.nextDouble(); } int[] numStudentsInSection = new int[numSections+1]; for (Student student : students) { double score = student.getScore(course); if (score != -1) { for (int i = 0; i < numSections; i++) { if (score >= sectionScores[i] && score < sectionScores[i+1]) { numStudentsInSection[i]++; break; } } } } for (int i = 0; i < numSections; i++) { System.out.println(sectionScores[i] + "到" + sectionScores[i+1] + "分的学生人数为:" + numStudentsInSection[i]); } } } class Student { private String id; private String name; private int age; private List<CourseScore> courseScores; public Student(String id, String name, int age) { this.id = id; this.name = name; this.age = age; this.courseScores = new ArrayList<>(); } public String getId() { return id; } public String getName() { return name; } public int getAge() { return age; } public void addCourseScore(Course course, List<Double> dailyScores, double examScore, double practiceScore, double finalScore) { this.courseScores.add(new CourseScore(course, dailyScores, examScore, practiceScore, finalScore)); } public double getScore(Course course) { for (CourseScore courseScore : courseScores) { if (courseScore.getCourse().equals(course)) { return courseScore.getScore(); } } return -1; } @Override public String toString() { StringBuilder sb = new StringBuilder(); for (CourseScore courseScore : courseScores) { sb.append(courseScore.getCourse().getName()).append("成绩:").append(courseScore.getScore()).append("\n"); } return sb.toString(); } } class Course { private String name; private double dailyScoreWeight; private double examScoreWeight; private double practiceScoreWeight; private double finalScoreWeight; public Course(String name, double dailyScoreWeight, double examScoreWeight, double practiceScoreWeight, double finalScoreWeight) { this.name = name; this.dailyScoreWeight = dailyScoreWeight; this.examScoreWeight = examScoreWeight; this.practiceScoreWeight = practiceScoreWeight; this.finalScoreWeight = finalScoreWeight; } public String getName() { return name; } public double getDailyScoreWeight() { return dailyScoreWeight; } public double getExamScoreWeight() { return examScoreWeight; } public double getPracticeScoreWeight() { return practiceScoreWeight; } public double getFinalScoreWeight() { return finalScoreWeight; } } class CourseScore { private Course course; private List<Double> dailyScores; private double examScore; private double practiceScore; private double finalScore; public CourseScore(Course course, List<Double> dailyScores, double examScore, double practiceScore, double finalScore) { this.course = course; this.dailyScores = dailyScores; this.examScore = examScore; this.practiceScore = practiceScore; this.finalScore = finalScore; } public Course getCourse() { return course; } public double getScore() { double dailyScoreSum = 0; for (double dailyScore : dailyScores) { dailyScoreSum += dailyScore; } double dailyScoreAverage = dailyScoreSum / dailyScores.size(); return dailyScoreAverage * course.getDailyScoreWeight() + examScore * course.getExamScoreWeight() + practiceScore * course.getPracticeScoreWeight() + finalScore * course.getFinalScoreWeight(); } } ``` 以上代码实现了一个学生成绩管理系统,包括学生信息、课程信息和课程成绩信息。每个学生可以学习多门课程,每门课程有多个成绩,包括平时成绩、其中考试成绩、实习成绩、期末考试成绩以及总评成绩等。可以实现以下功能: 1. 列出某个学生的所有成绩; 2. 列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分; 3. 分区段统计某门课程的学生总评成绩。

相关推荐

zip
基于PyTorch的Embedding和LSTM的自动写诗实验LSTM (Long Short-Term Memory) 是一种特殊的循环神经网络(RNN)架构,用于处理具有长期依赖关系的序列数据。传统的RNN在处理长序列时往往会遇到梯度消失或梯度爆炸的问题,导致无法有效地捕捉长期依赖。LSTM通过引入门控机制(Gating Mechanism)和记忆单元(Memory Cell)来克服这些问题。 以下是LSTM的基本结构和主要组件: 记忆单元(Memory Cell):记忆单元是LSTM的核心,用于存储长期信息。它像一个传送带一样,在整个链上运行,只有一些小的线性交互。信息很容易地在其上保持不变。 输入门(Input Gate):输入门决定了哪些新的信息会被加入到记忆单元中。它由当前时刻的输入和上一时刻的隐藏状态共同决定。 遗忘门(Forget Gate):遗忘门决定了哪些信息会从记忆单元中被丢弃或遗忘。它也由当前时刻的输入和上一时刻的隐藏状态共同决定。 输出门(Output Gate):输出门决定了哪些信息会从记忆单元中输出到当前时刻的隐藏状态中。同样地,它也由当前时刻的输入和上一时刻的隐藏状态共同决定。 LSTM的计算过程可以大致描述为: 通过遗忘门决定从记忆单元中丢弃哪些信息。 通过输入门决定哪些新的信息会被加入到记忆单元中。 更新记忆单元的状态。 通过输出门决定哪些信息会从记忆单元中输出到当前时刻的隐藏状态中。 由于LSTM能够有效地处理长期依赖关系,它在许多序列建模任务中都取得了很好的效果,如语音识别、文本生成、机器翻译、时序预测等。

最新推荐

recommend-type

学生成绩管理系统实验报告.doc

学生成绩管理系统,功能分为: (1)添加功能:程序能够添加不同学生的记录,提供选择界面供用户选择所要添加的类别,要求学号要唯一,如果添加了重复学号的记录时,则提示数据添加重复并取消添加。 (2)查询功能:...
recommend-type

数据库学生管理系统课程设计报告.doc

使用Visual Basic6.0语言和数据库建立连接,开发学生成绩管理系统,并且能成功运行,完成任务设计书中要求的功能。 2. 课程设计内容和要求 内容: 学生成绩管理系统 主要功能 1.用户登录窗口。 2.系统总控菜单窗口...
recommend-type

【java课设】学生选课系统.pdf

根据课程信息和学生信息完成对课程的选修,需要专门的一个管理类来完成选修工作。 2、功能要求 (1)添加功能:程序能够任意添加课程和学生记录,可提供选择界面供用户选择所要添加的类别,要求编号要唯一,如果添加...
recommend-type

C语言数组实现学生信息管理系统设计

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

学生信息管理学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail等。设计“学生信息管理系统”

学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail等。设计“学生信息管理系统”,使之能提供以下功能: 1)系统以菜单方式工作; 2)学生信息录入功能; 3)学生信息浏览功能; 4)查询、...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。