วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558

Lab8-display student by 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_weight(){
      return this.weight;
      }
     
   public int get_height(){
      return this.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 );
   }

   public static void main(String[] args){
      student S[] ={ new student("jinx",58102,18,44,164),
                            new student("Vi",58201,19,65,169),
                            new student("Kat",58101,20,70,160)};
      int i = 0;
      while(i<S.length){
         S[i].display();
         System.out.println();
         i+=1;
      }
   }
     

}

Result
name:  jinx
ID:    58102
age:   18
weight:44
height:164

name:  Vi
ID:    58201
age:   19
weight:65
height:169

name:  Kat
ID:    58101
age:   20
weight:70
height:160


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

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