วันอังคารที่ 1 ธันวาคม พ.ศ. 2558

Display each student record JAVA

public class Students {
   private String name;
   private int ID;
   private int age;
   private int weight;
   private int height;
 
   public Students(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 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);
     System.out.println();
   }
 
   public static void main(String[] args) {
      Students a = new Students ("AAA", 11111, 20, 60, 165);
      Students b = new Students ("BBB", 22222, 25, 65, 170);
      Students c = new Students ("CCC", 33333, 15, 55, 160);
      Students d = new Students ("DDD", 44444, 19, 50, 155);
   
      Students[] data = {a, b, c, d};
      display(data);
   }
 
   public static void display(Students[] data){
      int i = 0;
      while(i < data.length){
        data[i].display();
        i = i + 1 ;
      }
   }
}