package j2.lesson02_2;
public class ExamRecord2 {
String name;
int math;
int japanese;
int english;
public ExamRecord2(String name,
int math, int japanese, int english) {
this.name = name;
this.math = math;
this.japanese = japanese;
this.english = english;
}
public void show() {
System.out.println(this.name + ", 数学 = " + this.math
+ ", 国語 = " + this.japanese
+ ", 英語 = " + this.english
+ ", 3科目の平均 = "
+ ((this.math + this.japanese + this.english) / 3.0));
}
public static double averageMath(ExamRecord2[] ra){
int sum = 0;
for(int i=0; i<ra.length; i++){
sum += ra[i].math;
}
return (double)sum / ra.length;
}
public static double averageJapanese(ExamRecord2[] ra){
int sum = 0;
for(int i=0; i<ra.length; i++){
sum += ra[i].japanese;
}
return (double)sum / ra.length;
}
public static double averageEnglish(ExamRecord2[] ra){
int sum = 0;
for(int i=0; i<ra.length; i++){
sum += ra[i].english;
}
return (double)sum / ra.length;
}
}
|