วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558

Find/count number of students with age < 30.

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 String get_name(){
        return this.name;
  }

  public int get_ID(){
        return this.ID;
  }

  public int get_age(){
        return this.age;
  }

  public int get_weight(){
        return this.weight;
  }

  public int get_height(){
        return this.height;
  }

  public static void main(String[] args){
    Student a = new Student("Gun" , 32075, 26, 80, 174);
    Student b = new Student("Rit" , 32078, 25, 70, 170);
    Student c = new Student("Frame" , 32080, 19, 58, 173);
    Student d = new Student("Coffee"  , 32057, 18, 50, 168);
    Student e = new Student("Boat" , 32087, 16, 60, 165);
 
    Student [] data = {a,b,c,d,e};
    count(data);
  }

   public static void count(Student [] data){
      int i = 0;
      int count = 0;
      while(i < data.length){
         if(data[i].get_age() < 30){
         count = count + 1;
         
      }
          i = i + 1;
   
   }
       System.out.println("Have " + count + " students");
}
}

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

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

Link Video Presentation Resort Managemant System Project.

Video Presentation Resort Managemant System Project. จัดทำโดย พากษ์เสียง: คุณาสิน  ทองมณี  5801012620011 ลำดับภาพ: สุพิชชา  ศรีศิริ...