วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558

[LAB8] BMI #JAVA

public class DataStudent
{
  private String name;
  private int sID;
  private int age;
  private int height;
  private int weight;


  public DataStudent(String name, int sID, int age,  int height, int weight)
  {
    this.name = name;
    this.sID = sID;
    this.age = age;
    this.height = height;
    this.weight = weight;
  }

  public String get_name()
  {
    return this.name;
  }

  public float get_weight()
  {
    return this.weight;
  }

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

  public static void main(String[] args)
  {
    DataStudent[] s =
    {
      new DataStudent("Nop",20046,28,173,52),
      new DataStudent("Pee",20054,35,176,78),
      new DataStudent("Fern",20097,26,174,58),
    };
 
    //display_bmi_more_25
    int i = 0;
    while(i < s.length)
    {
      if(find_BMI_more25(s[i]) > 25)
         {
           System.out.println();
           System.out.println(s[i].get_name());
           System.out.println(String.format("%.2f",find_BMI_more25(s[i])));
         }
      i = i + 1;
    }
  }

  public static float find_BMI_more25(DataStudent sign)
  {
    float bmi = sign.get_weight()/((sign.get_height()/100) * (sign.get_height()/100));
    return bmi ;
  }
}

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

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