閱讀以下說明和Java程序,填充代碼中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
某學(xué)校在學(xué)生畢業(yè)時要對其成績進行綜合評定,學(xué)生的綜合成績(GPA)由其課程加權(quán)平均成績(Wg)與附加分(Ag)構(gòu)成,即GPA= Wg +Ag。
設(shè)一個學(xué)生共修了n門課程,則其加權(quán)平均成績 (Wg) 定義如下:
其中 ,gradei 、Ci 分別表示該學(xué)生第 i 門課程的百分制成績及學(xué)分。
學(xué)生可以通過參加社會活動或?qū)W科競賽獲得附加分(Ag)。學(xué)生參加社會活動所得的活動分(Apoints)是直接給出的,而競賽分(Awards)則由下式計算(一個學(xué)生最多可參加m項學(xué)科競賽):
其中 ,li 和 Si 分別表示學(xué)生所參加學(xué)科競賽的級別和成績。
對于社會活動和學(xué)科競賽都不參加的學(xué)生,其附加分按活動分為0計算。
下面的程序?qū)崿F(xiàn)計算學(xué)生綜合成績的功能,每個學(xué)生的基本信息由抽象類Student描述,包括學(xué)號(stuNo)、姓名(name) 、課程成績學(xué)分(grades) 和綜合成績 (GPA)等,參加社會活動的學(xué)生由類ActStudent描述,其活動分由Apoints表示,參加學(xué)科競賽的學(xué)生由類CmpStudent描述,其各項競賽的成績信息由awards表示。
【Java 代碼】
abstract class Student {
protected String name;
protected int stuNo;
protected double GPA; /*綜合成績*/
protected int [ ] [ ] grades; /*各門課程成績和學(xué)分*/
//其他信息略
public Student ( int stuNo ,String name ,int[ ] [ ] grades) {
this. stuNo = stuNo; grades; this.name = name; this.grades =
grades;
}
(1) ;
double computeWg( ){
int totalGrades = 0 ,totalCredits = 0;
for (int i = 0; i < grades.length; i++) {
totalGrades += grades [i] [0] * grades [i] [1] ;
totalCredits += grades [i] [1];
}
return (double)totalGrades / totalCredits;
}
}
class ActStudent extends Student {
private int Apoints;
ActStudent (int stuNo ,String name ,int[] [] grades ,int Apoints){
(2) ;
this. Apoints = Apoints;
}
public double getGPA( ) {
return GPA = (3) ;
}
}
class CmpStudent extends Student {
private int [ ] [ ] Awards;
CmpStudent (int stuNo ,String name ,int[ ] [ ] grades ,int[ ] [ ] awards) {
(4) ;
this.Awards = awards;
}
public double getGPA() {
int totalAwards = 0;
for (int i = 0; i < awards.length; i++) {
totalAwards += awards[i] [0] * awards[i] [1];
}
return GPA = (5) ;
}
}
public class GPASystem ( //以計算 3 個學(xué)生的綜合成績?yōu)榈惯M行測試
public static void main(String[] args) {
int [ ] [ ] g1= {{80,3} ,{90,2} ,{95,3} ,{85,4} ,(86 ,3}) ,
g2 = {{60,3} ,{60,2} ,{60,3} ,{60,4} ,(65 ,3}) ,
g3 = {{80,3} ,{90,2} ,{70,3} ,{65,4} ,(75 ,3}); //課程成績
int [ ][ ] e1 = ((2 ,3) ,{1,2}} ,e2 = {{1,3}}; //競賽成績
Student students[ ] = {
new ActStudent (101,"John" ,gl ,3), / /3 為活動分
new ActStudent (102 ,"Zhang" ,g2 ,0) ,
new CmpStudent (103,"Li",g3,e2)};
}
//輸出每個學(xué)生的綜合成績
for (int i = 0; i < students .length; i++) (
System.out,println( (6) );
}
}
}