public class student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
private float BMI;
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;
this.BMI = weight/((height/100)^2);
}
public float get_weight(){
return this.weight;
}
public void display(){
System.out.println("name: "+this.name );
System.out.println("ID: "+this.ID);
System.out.println("age: "+this.age);
System.out.println("weight:"+this.weight);
System.out.println( "height:"+this.height );
System.out.println("BMI:"+this.BMI);
}
public static void main(String[] args){
student S[] ={ new student("jinx",58102,18,44,164),
new student("Vi",58201,19,80,165),
new student("Kat",58101,20,70,160)};
System.out.println("The number of student who got weight less than 50 :"+count_weight_less_than_50(S));
display_weight_less_than_50(S);
}
public static int count_weight_less_than_50(student[] S){
int count = 0;
int i = 0;
while(i<S.length){
if(S[i].get_weight()<50){
count+=1;
}
i+=1;
}
return count;
}
public static void display_weight_less_than_50(student[] S){
int i = 0;
while(i<S.length){
if(S[i].get_weight()<50){
S[i].display();
}
i+=1;
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น