Java 实现:3 个学生成绩信息封装与总分、平均分计算
```java import java.util.Scanner; class Score { int usualScore; int finalScore; int calculateTotalScore() { return (int) (usualScore * 0.4 + finalScore * 0.6); } } class Student { String studentId; String name; Score chineseScore; Score mathScore; Score physicsScore; int calculateTotalScore() { return chineseScore.calculateTotalScore() + mathScore.calculateTotalScore() + physicsScore.calculateTotalScore(); } double calculateAverageScore() { return (double) calculateTotalScore() / 3; } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Student[] students = new Student[3]; for (int i = 0; i < 3; i++) { Student student = new Student(); System.out.print("请输入第" + (i + 1) + "个学生的学号:"); student.studentId = scanner.nextLine(); System.out.print("请输入第" + (i + 1) + "个学生的姓名:"); student.name = scanner.nextLine(); System.out.println("请输入第" + (i + 1) + "个学生的语文平时成绩和期末成绩:"); Score chineseScore = new Score(); chineseScore.usualScore = scanner.nextInt(); chineseScore.finalScore = scanner.nextInt(); student.chineseScore = chineseScore; System.out.println("请输入第" + (i + 1) + "个学生的数学平时成绩和期末成绩:"); Score mathScore = new Score(); mathScore.usualScore = scanner.nextInt(); mathScore.finalScore = scanner.nextInt(); student.mathScore = mathScore; System.out.println("请输入第" + (i + 1) + "个学生的物理平时成绩和期末成绩:"); Score physicsScore = new Score(); physicsScore.usualScore = scanner.nextInt(); physicsScore.finalScore = scanner.nextInt(); student.physicsScore = physicsScore; students[i] = student; scanner.nextLine(); // 处理输入流中的换行符 } for (Student student : students) { System.out.println("总分:" + student.calculateTotalScore()); System.out.printf("平均分:%.2f\n", student.calculateAverageScore()); } } } ``` ######[AI写代码神器 | 581点数解答 | 2024-11-19 15:54:02]
- C 语言:快速实现 5 个学生信息录入、按成绩升序排序并输出!(字节豆包 | 373点数解答 | 2024-10-30 00:37:20)409
- C语言实现:输入5名学生信息并按成绩升序排序输出(字节豆包 | 354点数解答 | 2024-10-30 18:45:58)353
- C语言:输入5个学生信息,按成绩升序排序并输出(字节豆包 | 373点数解答 | 2024-10-31 19:49:58)344
- C语言:输入5名学生信息并按成绩升序排序输出(字节豆包 | 326点数解答 | 2025-01-01 20:11:47)339
- Java 实现复制粘贴功能:打造简易文本复制粘贴程序(GPT | 1497点数解答 | 2024-08-25 09:40:33)403
- 成绩等级统计:20个60 - 100分成绩的等级数量揭秘(字节豆包 | 219点数解答 | 2025-04-09 10:20:32)218
- 培训机构学员成绩与年龄更新:C++ 代码实现(DeepSeek | 186点数解答 | 2025-12-16 18:04:31)58
- Python 处理培训机构学员培训后年龄与 NOIP 成绩提升情况(DeepSeek | 73点数解答 | 2025-12-16 18:05:20)61
- 培训机构学员成绩提升:C++代码实现年龄与NOIP成绩更新(DeepSeek | 178点数解答 | 2025-12-31 12:20:24)58
- 解决数据库“dm.jdbc.driver.dmexception: 数据溢出”问题的全步骤指南(阿里通义 | 598点数解答 | 2024-10-15 15:48:38)305
- 达梦数据库数据溢出问题排查及多维度解决方法(阿里通义 | 403点数解答 | 2024-10-15 15:48:41)1134
- Java:抽象类 Vehicle 及子类 Car、MotorBike 实战演示(讯飞星火 | 440点数解答 | 2024-06-06 23:18:54)310