package j2.lesson02_2;
public class ExamRecord5 {
String name; // Name
int id; // Id number
int ma; // mathematics
int jp; // japanes
int en; // english
int sc; // Science
int ss; // Social Studies
public ExamRecord5(String name, int id, int ma, int jp, int en, int sc, int ss){
this.name = name;
this.id = id;
this.ma = ma;
this.jp = jp;
this.en = en;
this.sc = sc;
this.ss = ss;
}
// 3科目(数学,国語,英語)の合計を返す
public int getTotal3(){
return ma+jp+en;
}
// 5科目(数学,国語,英語,理科,社会)の合計を返す
public int getTotal5(){
return ma+jp+en+sc+ss;
}
// 3科目(数学,国語,英語)の成績を表示する
public void show3(){
System.out.println(name + ", id=" + id + ", ma=" + ma +
", jp=" + jp + ", en=" + en);
}
// 5科目(数学,国語,英語,理科,社会)の成績を表示する
public void show5(){
System.out.println(name + ", id=" + id + ", ma=" + ma +
", jp=" + jp + ", en=" + en + ", sc=" + sc + ", ss=" + ss);
}
public static double getAverageMa(ExamRecord5[] ra){
double sum = 0.0;
for(int i=0; i<ra.length; i++){
sum += ra[i].ma;
}
return sum/ra.length;
}
public static double getAverageJp(ExamRecord5[] ra){
double sum = 0.0;
for(int i=0; i<ra.length; i++){
sum += ra[i].jp;
}
return sum/ra.length;
}
public static double getAverageEn(ExamRecord5[] ra){
double sum = 0.0;
for(int i=0; i<ra.length; i++){
sum += ra[i].en;
}
return sum/ra.length;
}
public static void sortByMath(ExamRecord5[] ra){
// Bubble sort
boolean changed = true;
while(changed){
changed = false;
for(int i=0; i<=ra.length-2; i++){
if(ra[i].ma < ra[i+1].ma){
ExamRecord5 temp = ra[i];
ra[i] = ra[i+1];
ra[i+1] = temp;
changed = true;
}
}
}
}
public static void sortByTotal5(ExamRecord5[] ra){
// Bubble sort
boolean changed = true;
while(changed){
changed = false;
for(int i=0; i<=ra.length-2; i++){
if(ra[i].getTotal5() < ra[i+1].getTotal5()){
ExamRecord5 temp = ra[i];
ra[i] = ra[i+1];
ra[i+1] = temp;
changed = true;
}
}
}
}
}
|