วันอาทิตย์ที่ 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();
   }


}

วันอังคารที่ 17 พฤศจิกายน พ.ศ. 2558

Report

A1
   -can't run on website
   -history have a problem
   -coin have a problem

Raspberry pi

def setup():
    S = [Student('Jinx',12,56),
         Student('Vi',13,25),
         Student('Garen',14,80),
         Student('Missfor',15,64),
         Student('Zed',16,85)]

    show_allGrade(S)
    print(count_grade('A',S))

class Student:
    def __init__(self,name,ID,score):
        self.name = name
        self.ID = ID
        self.score = score

    def get_score(self):
        return self.score

    def set_ID(self,score):
        self.score = score

    def display(self):
        print('name:',self.name)
        print('ID:',self.ID)
        print('score:',self.score)
       
   
def find_grade(score):
    if(score<50):
        return 'F'
    elif(score>=50 and score<60):
        return 'D'
    elif(score>=60 and score<70):
        return 'C'
    elif(score>=70 and score<80):
        return 'B'
    elif(score>=80):
        return 'A'

def count_grade(grade,S):
    i = 0
    count = 0
    while(i<len(S)):
        if(grade == find_grade(S[i].get_score())):
            count+=1
        i+=1  
    return count          

def show_allGrade(S):
    i = 0
    while(i<len(S)):
        S[i].display()
        print(find_grade(S[i].get_score()))
        print()
        i+=1
   
   
setup()

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

Complex

class Complex:
   def __init__(self,real_num,imagine_num=0):
      self.real_num = real_num
      self.imagine_num = imagine_num
 
   def get_real_num(self):
      return self.real_num

   def get_imagine_num(self):
      return self.imagine_num

   def add(self,b):
      real_num = self.real_num + b.get_real_num()
      imagine_num = self.imagine_num + b.get_imagine_num()
      c = Complex(real_num,imagine_num)
      return c

   def display(self):
      i = self.imagine_num
      if i<0 :
         print(self.real_num,end=" ")
      else:
         print(self.real_num,end="+")
      print(i,end="i")
      print()
 
def setup():
   a = Complex(5,-1)
   b = Complex(2,-1)
   c = Complex(0,0)
   c = a.add(b)
   a.display()
   b.display()
   c.display()
setup()