public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
average(data);
}
public static void average(Student [] data){
int i = 0;
int total = 0;
int n = 0;
float average = 0;
while(i < data.length){
total = total + data[i].get_age();
n = n + 1;
average = total/n;
i += 1 ;
}
System.out.println("average age = " + average);
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น