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

Lab08 : Student Class [Java]

public class Student {

 private String name;
 private int id;
 private int age;
 private int weight;
 private int height;

 public Student(String name,int id,int age, int weight,int height) {

   this.name = name;
   this.id = id;
   this.age = age;
   this.weight=weight;
   this.height=height;
 }
  public int get_w(){
   return this.weight; 
  }
  public int get_h(){
   return this.height; 
  }
  public int get_age(){
   return this.age; 
  }
  public String get_name(){
   return this.name ;
  }
  public void display(){
    System.out.println("Name :"+this.name); 
    System.out.println("ID :"+this.id); 
    System.out.println("AGE :"+this.age); 
    System.out.println("WEIGHT :"+this.weight); 
    System.out.println("HEIGHT :"+this.height); 
   }
  public static void main(String[] args) { 

  Student[] std={new Student("Roger",1,15,55,165),
                 new Student("Gold",2,18,49,173),
                 new Student("D",3,17,80,163)};
    display_student(std);
    bmi_student(std);
    age_student(std);
     weight_student(std);
 }
  public static void display_student(Student[] std){
     int i=0;
   while (i<std.length){
    std[i].display();
     i+=1;
   } 
  }
  public static void bmi_student(Student[] std){
    int i=0;
    int count=0;
    while (i<std.length){
      float m=(float)std[i].get_h()/100;
      System.out.print("BMI [ "+std[i].get_name()+" ] ="+(float)std[i].get_w()/(m*m));
      if ((float)std[i].get_w()/(m*m) > 25){
        count+=1;
          System.out.println("<--- (BMI >25)");
      } else {
       System.out.println();
      }
       i+=1;
    }
    System.out.println("count BMI > 25 = "+count);
   
  }
  public static void age_student(Student[] std){
   float avg=0;
    int i=0;
    int count=0;
    while (i<std.length){
     avg+=std[i].get_age(); 
      if (std[i].get_age()<30){
       count+=1; 
      }
      i+=1;
    }
    avg/=std.length;
    System.out.println("average age = "+avg);
    System.out.println("count age < 30 = "+count);
    
  }
  public static void weight_student(Student[] std){
    int min=std[0].get_w();
    int i=0;
    int count=0;
    while (i < std.length){
      if (std[i].get_w() < min){
       min=std[i].get_w(); 
      }
      if (std[i].get_w() < 50){
       count+=1; 
        std[i].display();
      }
      i+=1;
    }
    System.out.println("count Weight < 50 ="+count);
    
  }

}




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

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

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...