public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;
public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}
public void display(){
System.out.println("Name :"+this.name+"ID NO :"+this.idNO+"Age : "+this.age+"Weight : "+this.weight+"Height : "+this.height);
}
public static void main(String[] args){
Student[] a = {new Student("James",58001,13,177,90),
new Student("Jane",58002,15,140,60),
new Student("John",58003,17,156,54),
new Student("Jonas",58004,20,188,70)};
int i =0;
while(i<a.length){
a[i].display();
System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
i=i+1;
}
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
float w = a[i].get_weight();
float h = a[i].get_height();
bmi=w/((h/100)*(h/100));
return bmi;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น