定义一个Student类表示学生,有以下成员变量:姓名、语数外3门课高考成绩、第一志愿学校。假定有5所高校(每个学校的录取分数线不同),其中普通高校3个,重点高校2个(重点高校要求语文成绩必须高于90
时间: 2024-11-22 21:39:16 浏览: 27
定义一个`Student`类来表示学生,我们可以这样设计:
```java
public class Student {
private String name; // 姓名
private int mathScore; // 数学成绩
private int chineseScore; // 中文成绩
private int foreignScore; // 外语成绩
private int firstVolunteerSchoolGradeThreshold; // 第一志愿学校的录取分数线
// 普通高校的分数线数组
private static final int[] normalCollegesThresholds = {85, 80, 75};
// 重点高校的分数线数组
private static final int[] keyCollegesThresholds = {90, 85};
private String topUniversity; // 第一志愿学校
public Student(String name, int math, int chinese, int foreign, int threshold) {
this.name = name;
this.mathScore = math;
this.chineseScore = chinese;
this.foreignScore = foreign;
this.firstVolunteerSchoolGradeThreshold = threshold;
calculateTopUniversity();
}
private void calculateTopUniversity() {
if (chineseScore >= keyCollegesThresholds[0]) { // 如果语文成绩满足重点高校条件
for (int i = 0; i < keyCollegesThresholds.length; i++) {
if (mathScore + chineseScore + foreignScore >= keyCollegesThresholds[i]) {
this.topUniversity = "重点高校" + (i+1);
break;
}
}
} else {
for (int i = 0; i < normalCollegesThresholds.length; i++) {
if (mathScore + chineseScore + foreignScore >= normalCollegesThresholds[i]) {
this.topUniversity = "普通高校" + (i+1);
break;
}
}
}
}
// 获取和设置方法...
// ...
// 相关问题:
阅读全文