```java interface ComprehensiveScore { double calculateComprehensiveScore(); } class Student { private String studentId; private String name; private String gender; private int age; public Student(String studentId, String name, String gender, int age) { this.studentId = studentId; this.name = name; this.gender = gender; this.age = age; } public String getStudentId() { return studentId; } public String getName() { return name; } public String getGender() { return gender; } public int getAge() { return age; } @Override public String toString() { return "学号:" + studentId + " 姓名:" + name + " 性别:" + gender + " 年龄:" + age; } } class EnglishStudent extends Student implements ComprehensiveScore { private double speechScore; private double finalExamScore; private double midtermExamScore; public EnglishStudent(String studentId, String name, String gender, int age, double speechScore, double finalExamScore, double midtermExamScore) { super(studentId, name, gender, age); this.speechScore = speechScore; this.finalExamScore = finalExamScore; this.midtermExamScore = midtermExamScore; } @Override public double calculateComprehensiveScore() { return speechScore * 0.5 + finalExamScore * 0.25 + midtermExamScore * 0.25; } } class ComputerStudent extends Student implements ComprehensiveScore { private double operationAbilityScore; private double englishWritingScore; private double finalExamScore; private double midtermExamScore; public ComputerStudent(String studentId, String name, String gender, int age, double operationAbilityScore, double englishWritingScore, double finalExamScore, double midtermExamScore) { super(studentId, name, gender, age); this.operationAbilityScore = operationAbilityScore; this.englishWritingScore = englishWritingScore; this.finalExamScore = finalExamScore; this.midtermExamScore = midtermExamScore; } @Override public double calculateComprehensiveScore() { return operationAbilityScore * 0.4 + englishWritingScore * 0.2 + finalExamScore * 0.2 + midtermExamScore * 0.2; } } class LiteratureStudent extends Student implements ComprehensiveScore { private double speechScore; private double workScore; private double finalExamScore; private double midtermExamScore; public LiteratureStudent(String studentId, String name, String gender, int age, double speechScore, double workScore, double finalExamScore, double midtermExamScore) { super(studentId, name, gender, age); this.speechScore = speechScore; this.workScore = workScore; this.finalExamScore = finalExamScore; this.midtermExamScore = midtermExamScore; } @Override public double calculateComprehensiveScore() { return speechScore * 0.35 + workScore * 0.35 + finalExamScore * 0.15 + midtermExamScore * 0.15; } } public class Main { public static void main(String[] args) { // 创建可容纳 6 个学生的数组 Student[] students = new Student[6]; // 英语系学生 students[0] = new EnglishStudent("001", "张三", "男", 20, 80, 70, 60); students[1] = new EnglishStudent("002", "李四", "女", 21, 90, 80, 70); // 计算机系学生 students[2] = new ComputerStudent("003", "王五", "男", 22, 85, 75, 65, 75); students[3] = new ComputerStudent("004", "赵六", "女", 23, 95, 85, 75, 85); // 文学系学生 students[4] = new LiteratureStudent("005", "孙七", "男", 24, 80, 80, 70, 60); students[5] = new LiteratureStudent("006", "周八", "女", 25, 90, 90, 80, 70); for (Student student : students) { System.out.println(student.toString() + " 综合成绩:" + ((ComprehensiveScore) student).calculateComprehensiveScore()); } } } ``` 额外注意逻辑点: 1. 确保输入的成绩数据在合理范围内,避免出现异常结果。 2. 考虑添加异常处理机制,以应对可能出现的非法输入或计算错误。 3. 如果需要对学生信息进行修改或扩展功能,注意修改相关的类和方法。 [2025-05-13 18:55:25 | AI写代码神器 | 1215点数解答]