Java实现Student类:计算三门课程总分、平均分、最高分与最低分
以下是一个实现要求的Java代码: ```java public class Student { private String studentId; private String name; private double mathScore; private double englishScore; private double computerScore; public Student(String studentId, String name, double mathScore, double englishScore, double computerScore) { this.studentId = studentId; this.name = name; this.mathScore = mathScore; this.englishScore = englishScore; this.computerScore = computerScore; } public double getTotalScore() { return mathScore + englishScore + computerScore; } public double getAverageScore() { return getTotalScore() / 3; } public double getMaxScore() { return Math.max(mathScore, Math.max(englishScore, computerScore)); } public double getMinScore() { return Math.min(mathScore, Math.min(englishScore, computerScore)); } // Getters and setters public String getStudentId() { return studentId; } public void setStudentId(String studentId) { this.studentId = studentId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getMathScore() { return mathScore; } public void setMathScore(double mathScore) { this.mathScore = mathScore; } public double getEnglishScore() { return englishScore; } public void setEnglishScore(double englishScore) { this.englishScore = englishScore; } public double getComputerScore() { return computerScore; } public void setComputerScore(double computerScore) { this.computerScore = computerScore; } } ``` 下面是一个简单的测试示例: ```java public class StudentTest { public static void main(String[] args) { Student student1 = new Student("1001", "Alice", 85, 90, 78); System.out.println("Total Score: " + student1.getTotalScore()); System.out.println("Average Score: " + student1.getAverageScore()); System.out.println("Max Score: " + student1.getMaxScore()); System.out.println("Min Score: " + student1.getMinScore()); } } ``` 这个示例中,我们首先创建了一个名为"student1"的Student对象,并传入学号、姓名以及三门课程的成绩。然后我们通过调用相应的方法,计算总分、平均分、最高分和最低分,并打印输出这些结果。 ######[AI写代码神器 | 2332点数解答 | 2024-03-12 10:23:27]
- Java 实现复制粘贴功能:打造简易文本复制粘贴程序(GPT | 1497点数解答 | 2024-08-25 09:40:33)408
- 解决数据库“dm.jdbc.driver.dmexception: 数据溢出”问题的全步骤指南(阿里通义 | 598点数解答 | 2024-10-15 15:48:38)310
- 达梦数据库数据溢出问题排查及多维度解决方法(阿里通义 | 403点数解答 | 2024-10-15 15:48:41)1147
- MySQL 数据库操作:用德鲁伊连接池和 Spring JDBC 实现 MVC 架构下 Student 表操作及事务测试全解析(字节豆包 | 1115点数解答 | 2025-03-19 11:17:31)292
- Spring JDBC+德鲁伊连接池:MVC架构下MySQL学生表查询、事务验证及代码实现全解析(DeepSeek | 1275点数解答 | 2025-03-19 11:21:32)277
- Java 学生类代码优化:避免数据类型、命名及封装陷阱(DeepSeek | 464点数解答 | 2025-10-28 16:05:49)95
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)345
- Java实现Student类:计算三门课程总分、平均分、最高分与最低分( | 2332点数解答 | 2024-03-12 10:23:27)262
- Python 实战:学生信息列表转字典、遍历、深拷贝及数据修改全流程(GPT | 422点数解答 | 2024-10-29 15:43:54)417
- Python实战:学生成绩列表转字典,深拷贝与数据修改操作全解析(字节豆包 | 254点数解答 | 2024-10-29 16:01:39)409
- C语言:构建学生绩点链表,删除低绩点学生并输出新链表(字节豆包 | 604点数解答 | 2024-12-03 11:10:47)286
- Python 实现学生类设计:实例化对象、信息打印及逻辑注意点(字节豆包 | 321点数解答 | 2024-12-17 14:08:55)355