love

วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558

Lab8 - Display Student BMI (Java)

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;
    while(count<data.length){
      System.out.println("Name : "+data[count].get_name());
      System.out.println("ID : "+data[count].get_id());
      System.out.println("Age : "+data[count].get_age());
      System.out.println("Weight : "+data[count].get_weight());
      System.out.println("Height : "+data[count].get_height());
      System.out.println("BMI : " +data[count].get_bmi());
      System.out.println();
      count = count+1;
    }
  }
}

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

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