love

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

Lab8 - Find Minimum Weight of Students (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;
    float min = data[0].get_weight();
    float compare = 0;
    while(count<data.length){
      compare = data[count].get_weight();
      if(compare<min){
        min = compare;
      }
      count = count+1;
    }
    System.out.println("Minimum Weight of Student : " +min);
  }
}

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

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