Sunday, November 1, 2015

Lab8 - Find student BMI

public class Student {
  private String name;
  private int studentNumber;
  private int age;
  private int weight;
  private int height;
 
  public Student(String name, int studentNumber, int age, int weight, int height) {
    this.name = name;
    this.studentNumber = studentNumber;
    this.age = age;
    this.weight = weight;
    this.height = height;
  }
 
  public String display_name() {
    return this.name;
  }
 
  public int display_studentNumber() {
  return this.studentNumber ;
  }
 
  public int display_age(){
    return this.age;
  }
 
  public float display_weight() {
    return this.weight;
  }
 
  public float display_height() {
    return this.height;
  }
 
 
  public static void main(String[] args) {
    Student[] stu =  { new Student("Bird", 33, 22, 65, 170 ),
    new Student("Bryant", 24, 21, 58, 167 ),
    new Student("Paul", 3, 17, 57, 167 ),
    new Student("James", 23, 19, 62, 172 ),
        new Student("Nowitzki", 34, 21, 66, 177 ) };
    System.out.println ( " ##### Student Record #####" );
    display_data(stu) ;
  }
 
  public static void display_data(Student[] s) {
    float bmi;
    int i=0;
    while (i<s.length) {
      System.out.println( "Name : "+s[i].display_name() );
      System.out.println( "StudentNumber : " +s[i].display_studentNumber() );
      System.out.println( "Age : "+s[i].display_age() );
      System.out.println( "Weight : "+s[i].display_weight() );
      System.out.println( "Height : "+s[i].display_height() );
      bmi=s[i].display_weight()/((s[i].display_height()/100)*(s[i].display_height()/100));
      System.out.println("Your BMI is "+bmi);
      System.out.println( "" );
      i=i+1;
    }
  }
}

No comments:

Post a Comment