Java 实现学生信息管理类:计算成绩、统计人数全搞定
```java public class Student { private int id; private String name; private double chineseScore; private double mathScore; private static int studentCount = 0; public Student(int id, String name, double chineseScore, double mathScore) { this.id = id; this.name = name; this.chineseScore = chineseScore; this.mathScore = mathScore; studentCount++; } public double getTotalScore() { return chineseScore + mathScore; } public double getAverageScore() { return (chineseScore + mathScore) / 2; } public static void printStudentCount() { System.out.println("当前学生总数为:" + studentCount); } public void printStudentInfo() { System.out.println("姓名:" + name); System.out.println("学号:" + id); System.out.println("总成绩:" + getTotalScore()); System.out.println("平均成绩:" + getAverageScore()); System.out.println("----------------------------------"); } public static void main(String[] args) { Student student1 = new Student(1, "张三", 85, 90); Student student2 = new Student(2, "李四", 78, 88); student1.printStudentInfo(); student2.printStudentInfo(); Student.printStudentCount(); } } ``` 运行结果: ``` 姓名:张三 学号:1 总成绩:175.0 平均成绩:87.5 ---------------------------------- 姓名:李四 学号:2 总成绩:166.0 平均成绩:83.0 ---------------------------------- 当前学生总数为:2 ``` ######[AI写代码神器 | 1026点数解答 | 2024-09-29 16:14:21]
- C 语言:快速实现 5 个学生信息录入、按成绩升序排序并输出!(字节豆包 | 373点数解答 | 2024-10-30 00:37:20)411
- C语言实现:输入5名学生信息并按成绩升序排序输出(字节豆包 | 354点数解答 | 2024-10-30 18:45:58)356
- C语言:输入5个学生信息,按成绩升序排序并输出(字节豆包 | 373点数解答 | 2024-10-31 19:49:58)349
- C语言:输入5名学生信息并按成绩升序排序输出(字节豆包 | 326点数解答 | 2025-01-01 20:11:47)343
- Java 实现复制粘贴功能:打造简易文本复制粘贴程序(GPT | 1497点数解答 | 2024-08-25 09:40:33)408
- 用 Pandas 深度剖析数据:从读取到统计分析全流程实战(GPT | 642点数解答 | 2024-06-30 15:39:49)357
- 用 Pandas 深入分析招聘数据:从数据读取到可视化全流程解析(GPT | 1539点数解答 | 2024-06-30 15:56:50)373
- 成绩等级统计:20个60 - 100分成绩的等级数量揭秘(字节豆包 | 219点数解答 | 2025-04-09 10:20:32)219
- 培训机构学员成绩与年龄更新:C++ 代码实现(DeepSeek | 186点数解答 | 2025-12-16 18:04:31)61
- Python 处理培训机构学员培训后年龄与 NOIP 成绩提升情况(DeepSeek | 73点数解答 | 2025-12-16 18:05:20)65
- 培训机构学员成绩提升:C++代码实现年龄与NOIP成绩更新(DeepSeek | 178点数解答 | 2025-12-31 12:20:24)61
- 解决数据库“dm.jdbc.driver.dmexception: 数据溢出”问题的全步骤指南(阿里通义 | 598点数解答 | 2024-10-15 15:48:38)310