วันอังคารที่ 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()

Fraction

class Fraction:
   def __init__(self,numerator,denominator):
      self.numerator = numerator
      self.denominator = denominator
   
   def get_numerator(self):
      return self.numerator
 
   def get_denominator(self):
      return self.denominator

   def add(self,b):    
      c_numerator = self.numerator*b.get_denominator() + b.get_numerator()*self.denominator
      c_denominator = self.denominator*b.get_denominator()
      c = Fraction(c_numerator,c_denominator)
      return c
       
   def display(self):
      print(self.numerator,'/',self.denominator)
   
def setup():
   a = Fraction(5,3)
   b = Fraction(4,7)
   c = a.add(b)
   a.display()
   print('+')
   b.display()
   print('=')
   c.display()
setup()

vector

class Vector:
   def __init__(self,i,j):
      self.i = i
      self.j = j
 
   def get_i(self):
      return self.i

   def get_j(self):
      return self.j

   def add(self,b):
      c_i = self.i + b.get_i()
      c_j = self.j + b.get_j()
      c = Vector(c_i,c_j)
      return c
   
   def display(self):
        #print('(')
        print('(',self.i,end='i')
        if(self.j>0):
          print('+',self.j,end='j')
        print(')')
 
def setup():
   a = Vector(5,3)
   b = Vector(4,7)
   c = a.add(b)
   a.display()
   print('+')
   b.display()
   print('=')
   c.display()
setup()

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

Lab6-banner

def setup():
   set_word('FOX')

def set_word(word):
   F1="# # # # #"
   F2="#"
   F3="# # # #"
   F4="#"
   F5="#"
   F6="#"
   F = [F1,F2,F3,F4,F5,F6]
   O1=" # # # # "
   O2="#       #"
   O3="#       #"
   O4="#       #"
   O5="#       #"
   O6=" # # # # "
   O=[O1,O2,O3,O4,O5,O6]
   X1="#       #"
   X2="  #   #  "
   X3="    #    "
   X4="    #    "
   X5="  #   #  "
   X6="#       #"
   X =[X1,X2,X3,X4,X5,X6]

   word_i = 0
   alphabet_i = 0
   while(alphabet_i<6):
      alphabet_i = 0
      while(word_i<len(word)):
         if(word[alphabet_i] == 'F'):
            print(F[word_i])
         elif(word[alphabet_i] == 'O'):
            print(O[word_i])
         elif(word[alphabet_i] == 'X'):
            print(X[word_i])
         alphabet_i+=1
      print()
      word_i+=1
setup()

Lab7-banner

class banner:
   def __init__(self,word,char):
      self.word = word
      self.char = char
 
   def set_word(self):
      F1="# # # # #"
      F2="#"
      F3="# # # #"
      F4="#"
      F5="#"
      F6="#"
      F = [F1,F2,F3,F4,F5,F6]
      O1=" # # # # "
      O2="#       #"
      O3="#       #"
      O4="#       #"
      O5="#       #"
      O6=" # # # # "
      O=[O1,O2,O3,O4,O5,O6]
      X1="#       #"
      X2="  #   #  "
      X3="    #    "
      X4="    #    "
      X5="  #   #  "
      X6="#       #"
      X =[X1,X2,X3,X4,X5,X6]


      my_replace(F,'#',self.char)
      my_replace(O,'#',self.char)
      my_replace(X,'#',self.char)
 
      word_i = 0
      alphabet_i = 0
      while(word_i<len(self.word)):
         while(alphabet_i<6):
            if(self.word[word_i] == 'F'):
               print(F[alphabet_i])
            elif(self.word[word_i] == 'O'):
               print(O[alphabet_i])
            elif(self.word[word_i] == 'X'):
               print(X[alphabet_i])
            alphabet_i+=1
         alphabet_i = 0
         print()
         word_i+=1

   
def my_replace(word,old,new):
   newWord = ""
   i = 0
   j = 0
   while(i < len(word)):
      while(j< len(word[i])):      
         if(word[i][j] != old[0]):
            newWord += word[i][j]
            j += 1
         else:
            num = 0
            while(num < len(old) and old[num] == word[i][j+num]):
               num += 1
            if(num == len(old)):
               newWord += new
               j += len(old)
      word[i] = newWord
      newWord = ""
      j = 0    
      i+=1              


def setup():
   b = banner('FOX','&')
   b.set_word()

setup()

วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558

Lab8-display student by java

public class student{

      private String name;
      private int ID;
      private int age;
      private int weight;
      private int height;
     
      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;
   
      }

   public int get_weight(){
      return this.weight;
      }
     
   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 );
   }

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

}

Result
name:  jinx
ID:    58102
age:   18
weight:44
height:164

name:  Vi
ID:    58201
age:   19
weight:65
height:169

name:  Kat
ID:    58101
age:   20
weight:70
height:160