love

วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558

Lab8 - Count number of student >50

public class student{
  private String name;
  private int id;
  private int age;
  private float weight;
  private float height;

  public student(String name,int id,int age,float weight,float 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 float get_weight(){
    return this.weight;
  }

  public float get_height(){
    return this.height;
  }

  public float get_bmi(){
    float bmi = this.weight/((this.height/100)*(this.height/100));
    return bmi;
  }

  public static void main(String[] args){
    student a = new student("Oat",1,18,52,165);
    student b = new student("Nice",2,19,50,170);
    student c = new student("Loemax",3,19,65,170);
    student d = new student("Shin",4,19,63,168);
    student [] data = {a,b,c,d};

    display(data);
  }

  public static void display(student [] data){
    int count = 0;
    int num =0;
    while(count<data.length){
      if(data[count].get_weight()<50){
        num++;
      }
      count++;
    }
    System.out.println("Number of students with weight<50 : " +num);
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น