วันอาทิตย์ที่ 6 ธันวาคม พ.ศ. 2558

Lab8-Weight

public class student{

      private String name;
      private int ID;
      private int age;
      private int weight;
      private int height;
      private float BMI;

      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;
        this.BMI = weight/((height/100)^2);

      }

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

   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("BMI:"+this.BMI);
   }
   public static void main(String[] args){
      student S[] ={ new student("jinx",58102,18,44,164),
                            new student("Vi",58201,19,80,165),
                            new student("Kat",58101,20,70,160)};
     
      System.out.println("The number of student who got weight less than 50 :"+count_weight_less_than_50(S));
      display_weight_less_than_50(S);
 
   }
   public static int count_weight_less_than_50(student[] S){
      int count = 0;
      int i = 0;
      while(i<S.length){
         if(S[i].get_weight()<50){
            count+=1;
         }
         i+=1;
      }
      return count;
   }

   public static void display_weight_less_than_50(student[] S){
      int i = 0;
      while(i<S.length){
         if(S[i].get_weight()<50){
            S[i].display();
         }
         i+=1;
      }


   }

}

Lab8-BMI

public class student{

      private String name;
      private int ID;
      private int age;
      private int weight;
      private int height;
      private float BMI;
   
      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;
        this.BMI = weight/((height/100)^2);
 
      }

   public float get_BMI(){
      return this.BMI;
   }
   
   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 );
      System.out.println("BMI:"+this.BMI);
   }

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

}

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

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

Lab8-banner

public class banner{
   String word,character;
   public banner(String word){
      this.word = word;
      //this.character = character;
   }

   public void show(){
      String F1="# # # # #";
      String F2="#";
      String F3="# # # #";
      String F4="#";
      String F5="#";
      String F6="#";
      String[] F = {F1,F2,F3,F4,F5,F6};
      String O1=" # # # # ";
      String O2="#        #";
      String O3="#        #";
      String O4="#        #";
      String O5="#        #";
      String O6=" # # # # ";
      String[] O={O1,O2,O3,O4,O5,O6};
      String X1="#       #";
      String X2="  #   #  ";
      String X3="    #    ";
      String X4="    #    ";
      String X5="  #   #  ";
      String X6="#       #";
      String[] X ={X1,X2,X3,X4,X5,X6};
   
   
      int word_i = 0;
      while(word_i<this.word.length()){
         int alphabet_i = 0;
         while(alphabet_i<F.length){
            if(word.charAt(word_i) == 'F'){
               System.out.println(F[alphabet_i]);
            }else if(word.charAt(word_i) == 'O'){
               System.out.println(O[alphabet_i]);
            }else if(word.charAt(word_i) == 'X'){
               System.out.println(X[alphabet_i]);
            }
            alphabet_i+=1;
         }
        System.out.println();
        word_i+=1;
      }
   }
   public static void main(String[] arg){
      String word = "FOX";
      banner b = new banner(word);
      b.show();
   }


}