วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558

[LAB8] AGE #JAVA

public class DataStudent
{
  private String name;
  private int sID;
  private int age;
  private int height;
  private int weight;


  public DataStudent(String name, int sID, int age,  int height, int weight)
  {
    this.name = name;
    this.sID = sID;
    this.age = age;
    this.height = height;
    this.weight = weight;
  }

  public String get_name()
  {
    return this.name;
  }

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

  public static void main(String[] args)
  {
    DataStudent[] s =
    {
      new DataStudent("Nop",20046,28.0,173,52),
      new DataStudent("Pee",20054,35.0,176,78),
      new DataStudent("Fern",20097,26.0,174,58),
    };
    //System.out.println(find_average(s));
    //System.out.println(find_age_less30(s));
    System.out.println(Sort_Age(s))
  }
 
 
  public static float find_average(DataStudent s)
  {
    float i = 0;
    float total = 0;
    float a = 0;
    while(i < s.length)
    {
      total = total + s[i].get_age() ;
      i = i + 1 ;
    }
    a = total / s.length ;
    return a ;
  }

  public static int find_age_less30(DataStudent[] s)
  {
    int c = 0;
    while(int i = 0 < student.length)
    {
      if(s[i].get_age() < 30)
      {
        c = c + 1;
      }
    }
    return c;
  }

  public static void Sort_Age(Student[] student)
  {
  for (int i = 1; i < student.length; i++)
  {
   Student currentStudent = student[i];
   int pos = i;
   while(pos > 0 && student[pos - 1].get_age() > currentStudent.get_age())
   {
    student[pos] = student[pos - 1];
    pos = pos - 1;
   }
   student[pos] = currentStudent;
  }
 }
}

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

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