วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558

lab in class room

class Person:
   def __init__(self,name,age,weight,height):
      self.name = name
      self.age = age
      self.weight = weight
      self.height = height
     
   def get_name(self):
      return self.name
 
   def get_age(self):
      return self.age
 
   def get_weight(self):
      return self.weight
 
   def get_height(self):
      return self.height
 
class Student(Person):
   def __init__(self,name,age,weight,height,student_id):
      super().__init__(name,age,weight,height)
      self.student_id = student_id
     
   def get_student_id(self):
      return self.student_id
 
def find_bmi(data_person):
   bmi = data_person.get_weight()/(((data_person.get_height())/100)*((data_person.get_height())/100))
   print( bmi )
 
 
def main():
   a = Student("X","1",50,150,"111")
   b = Person ("S","12",60,170)
   c = Student("Y","2",55,155,"112")
   data_student  = [ a,c ]
   print (a.get_age())
   print (a.get_student_id())
   print (b.get_age())
   print (data_student[1].get_age())
   print (data_student[1].get_student_id())
   find_bmi(a)
 
main()

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

LAB 8 BANNER uncom

public class set {
    public String row1;
    public String row2;
    public String row3;
    public String row4;
    public String row5;
    static String X = "+";
    public String data_import;
    public set(String data){
        check(data);
        data_import = data;

    }
   
    public void check(String data){
        if(null != data)switch (data) {
            case "A":
                row1 = "     "+X+"     ";
                row2 = "    "+X+" "+X+"    ";
                row3 = "   "+X+" "+X+" "+X+"   ";
                row4 = "  "+X+"     "+X+"  ";
                row5 = " "+X+"       "+X+" ";
                break;
            case "B":
                row1 = " "+X+" "+X+" "+X+" "+X+"  ";
                row2 = " "+X+"      "+X+" ";
                row3 = " "+X+" "+X+" "+X+" "+X+"  ";
                row4 = " "+X+"      "+X+" ";
                row5 = " "+X+" "+X+" "+X+" "+X+"  ";
                break;
            case "C":
                row1 = "  "+X+X+X+X+X+X+X+" ";
                row2 = " "+X+"        ";
                row3 = " "+X+"        ";
                row4 = " "+X+"        ";
                row5 = "  "+X+X+X+X+X+X+X+" ";
                break;
            default:
                row1 = "         ";
                row2 = "         ";
                row3 = "         ";
                row4 = "         ";
                row5 = "         ";
                break;
        }    
    }
   
    public String get_row(int row){
        if(0 != row)switch (row) {
            case 1:
                return row1;

            case 2:
                return row2;

            case 3:
                return row3;

            case 4:
                return row4;

            case 5:
                return row5;

        }
        return "";
    }
   
    public void get_char_srting(String char_){
        X = char_;
    }
   
    public String get_data_import(){
    return data_import;
}
}



public class main {
    public static void main(String[] args){
        set[] data = {new set("A"),new set("B"),new set("C")};
        display(data);
        set_char(data,"x");
        display(data);
       
    }
   
    public static void display(set[] data){
        int count_char = 0;
        while(count_char<6){
            int count = 0;
            while(count<3){
                System.out.print(data[count].get_row(count_char));
                count +=1;
            }
            count_char +=1;
            System.out.println("");
        }
    }
   
    public static void set_char(set[] data,String char_){
        int count_char = 0;
        while(count_char<data.length){
            data[count_char].get_char_srting(char_);
            data[count_char] = new set(data[count_char].get_data_import());
            count_char +=1;
        }
    }

   }


ผลลัพธ์

      +      + + + +      +++++++
    + +     +      +     +      
   + + +   + + + +   +      
  +     +   +      +     +      
 +       +  + + + +     +++++++

      x      x x x x     xxxxxxx
    x x     x      x    x      
   x x x   x x x x   x      
  x     x   x      x    x      
 x       x  x x x x     xxxxxxx

LAB 8 WEIGHT

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
    static int count;
 
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    count +=1;
    }
 
    public int get_age(){
        return age;
    }
 
    public int get_wei(){
        return weight;
    }
 
    public int get_hei(){
        return height;
    }
 
    public int get_id(){
        return id;
    }
 
    public String get_name(){
        return name;
    }
 
   
 
    public void display_name(){
        System.out.println ("Name is "+name);
    }
 
    public void display_age(){
        System.out.println ("Age is "+age);
    }
 
    public void display_id(){
        System.out.println ("id is "+id);
    }
 
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
 
    public void display_height(){
        System.out.println ("height is " +height);
    }
 
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
 
    public int get_count(){
        return count;
    }
 
 
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
 

}


public class main {
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                                      new data_student("B",02,16,98,165),
                                      new data_student("C",03,18,45,168),
                                      new data_student("D",04,17,80,150)};
       
        System.out.println ("count weight low 50 is "+count_weiL50(data));
        display_data(data);

       
    }
   
    public static int get_minimum(data_student[] data){
        int count =0;
        int result = 0;
        while(count<data.length){
            if(data[count].get_wei()>result){
                result = data[count].get_wei();
            }
            count += 1;
        }
        return result;
    }
   
    public static int count_weiL50(data_student[] data){
        int count =0;
        int result = 0;
        while(count<data.length){
            if(data[count].get_wei()<50){
                result +=1;
            }
            count +=1;
        }
        return result;
    }
   

   
    public static void display_data(data_student[] data){
        int count =0;
        while(count<data.length){
            if(data[count].get_wei()<50){
                data[count].display_data();
        }
        count +=1;
        }
    }
}

ผลลัพธ์

count weight low 50 is 1
Name is C
id is 3
Age is 18
weight is 45
height is 168
BMI is 15

LAB 8 AGE

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
    static int count;
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    count +=1;
    }
   
    public int get_age(){
        return age;
    }
   
    public int get_wei(){
        return weight;
    }
   
    public int get_hei(){
        return height;
    }
   
    public int get_id(){
        return id;
    }
   
    public String get_name(){
        return name;
    }
   
     public void set_name(String name_){
        name = name_;
    }
   
     public void set_id(int id_){
        id = id_;
    }
   
     public void set_age(int age_){
        age = age_;
    }
   
     public void set_hei(int hei){
        height = hei;
    }
   
    public void set_wei(int wei){
        weight = wei;
    }
   
   
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
   
    public int get_count(){
        return count;
    }
   
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
   

}


public class main {
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                                      new data_student("B",02,16,98,165),
                                      new data_student("C",03,18,65,168),
                                      new data_student("D",04,17,80,150)};
        System.out.print(find_everage(data));
        System.out.println(" ");
        sort(data);
        display_data(data);
       
    }
    public static int find_everage(data_student[] data){
        int sum_age = 0;
        int average;
        for(int count =0;count<(data.length);count+=1){
            sum_age += data[count].get_age();
        }
        average = sum_age/data.length;
        return average;
        }
   
    public static boolean check(data_student[] data){
        int count =0;
        while(count<(data.length)-1){
            if(data[count].get_age()>data[count+1].get_age()){
                return true;
            }
            count +=1;
        }
        return false;
    }
   
    public static void sort(data_student[] data){
        int count =1;
        while(check(data)){
            if(data[count].get_age()<data[count-1].get_age()){
                int backup_id = data[count].get_id();
                String backup_name = data[count].get_name();
                int backup_age = data[count].get_age();
                int backup_height = data[count].get_hei();
                int backup_weight = data[count].get_wei();
               
                data[count].set_id((data[count-1]).get_id());
                data[count].set_age((data[count-1]).get_age());
                data[count].set_name((data[count-1]).get_name());
                data[count].set_hei((data[count-1]).get_hei());
                data[count].set_wei((data[count-1]).get_wei());
               
                data[count-1].set_id(backup_id);
                data[count-1].set_age(backup_age);
                data[count-1].set_name(backup_name);
                data[count-1].set_hei(backup_height);
                data[count-1].set_wei(backup_weight);
               
            }
            count +=1;
            if(count == data.length){
                count =1;
            }
        }
    }
   
    public static void display_data(data_student[] data){
        int count = 0;
        while(count<data.length){
            data[count].display_data();
            count +=1;
        }
    }
}

ผลลัพธ์

run:


15
Name is A
id is 1
Age is 10
weight is 55
height is 167
BMI is 18

Name is B
id is 2
Age is 16
weight is 98
height is 165
BMI is 32

Name is D
id is 4
Age is 17
weight is 80
height is 150
BMI is 21

Name is C
id is 3
Age is 18
weight is 65
height is 168
BMI is 26

BUILD SUCCESSFUL (total time: 0 seconds)


วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2558

LAB Fraction

class fraction:
   def __init__(self,numberator,denominator=1):
      self.num = numberator
      self.deno = denominator
     
   def get_num(self):
      return self.num
 
   def get_deno(self):
      return self.deno
 
   def sum_fraction_number(self,b):
      return (self.num*b.get_deno())+(b.get_num()*self.deno)
     
   def sum_fraction_deno(self,b):
      return (self.deno*b.get_deno())
     
   def display(self):
      if(self.deno>0):
         print (self.num," / ",self.deno)
      else:
         print (" Can't be calculated ")
 
def setup():
   a = fraction(2,4)
   b = fraction(5,0)
   d = fraction(7,3)
   c = fraction((a.sum_fraction_number(d)),(a.sum_fraction_deno(b)))
   f = fraction((a.sum_fraction_number(d)),(a.sum_fraction_deno(d)))
   a.display()
   b.display()
   c.display()
   f.display()

 
 
setup()


ผลลัพธ์

2  /  4
 Can't be calculated 
 Can't be calculated 
34  /  12

LAB IN CLASS

class complex:
   def __init__(self,real,imag):
      self.real = real
      self.imag = imag
      self.valu_imag = self.imag*((-1)**0.5)
     
   def display(self):
      if(self.imag>0):
         print (self.real," + ",self.imag,"i")
      elif(self.imag<0):
         print (self.real," - ",(-1)*self.imag,"i")
      else:
         print (self.real)
     
   def get_real(self):
      return self.real
 
   def get_imag(self):
      return self.imag
     
   def add_real(self,obj):
      return self.real + obj.get_real()
 
   def add_imag(self,obj):
      return self.imag + obj.get_imag()
     
     

 
def setup():
   a = complex(1,2)
   b = complex(3,-4)
   a.display()
   c = complex(a.add_real(b),a.add_imag(b))
   c.display()
 
 
 
setup()

ผลลัพธ์

1  +  2 i
4  -  2 i

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

LAB 8 BMI

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    }
   
    public int get_bmi(){
        return bmi;
    }
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
   

}


public class main {
   
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                               new data_student("B",02,16,98,165),
                               new data_student("C",03,18,65,168),
                               new data_student("D",04,17,80,150)};
       
        for(int count =0;count<data.length;count +=1){
            if(data[count].get_bmi()>25){
                data[count].display_data();
            }
        }
       
    }
   
}
       
       
ผลลัพ


Name is B
id is 2
Age is 16
weight is 98
height is 165
BMI is 32

Name is D
id is 4
Age is 17
weight is 80
height is 150
BMI is 26

LAB 8 JAVA.DISPLAY DATA

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    static int count=0;
   
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    count +=1;
    }
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        System.out.println(" ");
    }

}


public class main {
    static int[] main_data;
    public static void main(String[] args) {
        data_student a = new data_student("A",01,10,50,160);
        data_student b = new data_student("B",02,15,64,170);
        data_student c = new data_student("C",03,7,49,155);
       
        a.display_data();
        b.display_data();
        b.display_data();
       
    }

}


ผลลัพธ์

Name is A
id is 1
Age is 10
weight is 50
height is 160
 
Name is B
id is 2
Age is 15
weight is 64
height is 170
 
Name is B
id is 2
Age is 15
weight is 64
height is 170


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

REPORT RASPBERRY

สิ่งที่ได้เรียนรู้


    - เรียนรู้วิธีการใช้งาน Raspberry เบื้องต้น และใช้งาน python

ความรู้สึก

    - มันช้าไปหน่อย อืดๆ แต่ก็ น่าจะปรกติ เพราะ มันค่อนข้างเล็ก

   - เน็ท ช้ามาก ใช้เวลา ต่อเว็ปต่างๆนาน ทำให้เสียเวลา

lab raspberry

class student:
    def __init__(self,name,iD,score):
        self.name = name
        self.id = iD
        self.score = score

    def display_name(self):
        print('name is',self.name)

    def display_id(self):
        print('id is ',self.id)

    def display_score(self):
        print('score is',self.score)

    def display_all(self):
        print("...................")
        self.display_name()
        self.display_id()
        self.display_score()

    def get_score(self):
        return self.score

    def set_score(self):
        self.score = score


def getGrade(score):
     if(score >=80):
        return "A"
     elif(score >=70):
        return "B"
     elif(score >=60):
        return "C"
     elif(score >=50):
        return "D"
     else:
        return  "F"


       
def  count_grade(obj):
    A = 0
    B = 0
    C = 0
    D = 0
    F = 0
    count = 0
    while(count < len(obj)):
        if(getGrade(obj[count].get_score()) == "A"):
            A+= 1
        elif(getGrade(obj[count].get_score()) == 'B'):
            B += 1
        elif(getGrade(obj[count].get_score()) == 'C'):
            C += 1
        elif(getGrade(obj[count].get_score())== 'D'):
            D += 1
        elif(getGrade(obj[count].get_score())== 'F'):
            F += 1
        count +=1
    print("........................")
    print("have grade A" ,A ,"person")
    print("have grade B" ,B,"person")
    print("have grade C" ,C,"person")
    print("have grade D" ,D ,"person")
    print("have grade F" ,F, "person")
       
 
   
def show_all_grade(obj):
    count = 0
    while(count< len(obj)):
        obj[count].display_all()
        print("have grade",getGrade(obj[count].get_score()))
        count +=1

       
       
def setup():
    data_student = [ student('joker',1,80),
                     student('Mind',2,70),
                     student('Eiei',3,87),
                     student('Gigi',4,50),
                     student('Hihi',5,65)]
    show_all_grade(data_student)
    count_grade(data_student)
   
    print("student 1 have grade is",getGrade(data_student[0].get_score()))


setup()