package j2.lesson01_2;
public class ExamRecordAction3 {
public static void main(String[] args) {
ExamRecord[] rec = new ExamRecord[4];
rec[0] = createExamRecord("Taro", 50, 90, 100);
rec[1] = createExamRecord("Hanako", 70, 30, 80);
rec[2] = createExamRecord("Kenji", 60, 50, 70);
rec[3] = createExamRecord("Aya", 40, 100, 90);
for (int i = 0; i < rec.length; i++) {
showExamRecord(rec[i]);
}
}
public static ExamRecord createExamRecord(String name,
int math, int japanese, int english ) {
ExamRecord r = new ExamRecord();
r.name = name;
r.math = math;
r.japanese = japanese;
r.english = english;
return r;
}
public static void showExamRecord(ExamRecord r) {
System.out.println(r.name + ", 数学 = " + r.math
+ ", 国語 = " + r.japanese
+ ", 英語 = " + r.english
+ ", 3科目の平均 = "
+ ((r.math + r.japanese + r.english) / 3.0));
}
}
|