แสดงบทความที่มีป้ายกำกับ Lab 8 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Lab 8 แสดงบทความทั้งหมด

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

Lab8_Find_>_25


public class Student {
 private String name;
 private int idNO;
 private int age;
 private int weight;
 private int height;

 public Student(String name,int idNO,int age,int weight,int height){
 this.name = name;
 this.idNO = idNO;
 this.age = age;
 this.height = height;
 this.weight = weight;
}
public int get_age(){
return this.age;
}

public void display(){
 System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
  Student[] a =  {new Student("James",58001,13,177,90),
        new Student("Jane",58002,15,140,60),
        new Student("John",58003,17,156,54),
        new Student("Jonas",58004,20,188,70)};
 int i =0;
    while(i<a.length){
     a[i].display();
     System.out.println("this "+find_more_25(a,i)+" older than 25");
     i=i+1;
    }
 }

public static String find_more_25(Student[] a,int i){
String n="";
if(a[i].get_age()>25){
n=("one");
}else{
    n=("one not");
}
return n ;
}
}

Lab8_Avg_age


public class Student {
 private String name;
 private int idNO;
 private int age;
 private int weight;
 private int height;

 public Student(String name,int idNO,int age,int weight,int height){
 this.name = name;
 this.idNO = idNO;
 this.age = age;
 this.height = height;
 this.weight = weight;
}
public int get_age(){
return this.age;
}

public void display(){
 System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
  Student[] a =  {new Student("James",58001,13,177,90),
        new Student("Jane",58002,15,140,60),
        new Student("John",58003,17,156,54),
        new Student("Jonas",58004,20,188,70)};
 int i =0;
    while(i<a.length){
     a[i].display();
     i=i+1;
    }
    System.out.print("the avg. age is "+cal_avg_age(a));
 }
public static float cal_avg_age(Student[] a){
int i = 0;
int sums = 0 ;
float avg = 0 ;
while(i<a.length){
int age=a[i].get_age();
   sums = sums+age;
   avg = sums/a.length;
   i=i+1;  
}
return avg;
}
}

Lab8_Student_Find_More_BMI(25)


public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;

public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}

public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);

}

public static void main(String[] args){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
    System.out.println("this "+find_more_BMI(a,i)+" has > 25");
    i=i+1;
    }
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
     float w = a[i].get_weight();
     float h = a[i].get_height();
     bmi=w/((h/100)*(h/100));

return bmi;
}
public static String find_more_BMI(Student[] a,int i){
  String n ="";
  if(cal_bmi(a,i)>25){
     n =("one");
}else{
     n=("one not");}
  return n;
}
}

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

Lab8_Student_BMI


public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;

public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}

public void display(){
System.out.println("Name :"+this.name+"ID NO :"+this.idNO+"Age : "+this.age+"Weight : "+this.weight+"Height : "+this.height);
}

public static void main(String[] args){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
    i=i+1;
    }
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
     float w = a[i].get_weight();
     float h = a[i].get_height();
     bmi=w/((h/100)*(h/100));

return bmi;
}
}

Lab8_Student_Display


public class Student {
private String name;
private int idNO;
private int age;
private int weight;
private int height;

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

public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    i=i+1;
    }
}
}