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

A2 Video

https://www.youtube.com/watch?v=YguVTk60rag&feature=youtu.be

[LAB_INTRO] Raseberry pi

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

    def display(self):
        print(self.name)
        print(self.ID)
        print(self.score)

    def get_name(self):
        return self.name

    def get_score(self):
        return self.score

def setup():
    A = Student('Bung',10041,86)
    B = Student('Ploy',20119,75)
    C = Student('Toffy',20042,71)
    D = Student('Game',20145,65)
    E = Student('Mew',30078,79)
    Total = [A,B,C,D,E]
    print(find_grade(C))
    print(count_grade('A',Total))
    print()
    show_allGtade(Total)

def find_grade(i):
    char = ''
    score = i.get_score()
    if(score >= 80):
        char = 'A'
    elif(score >= 70 and score <= 79):
        char = 'B'
    elif(score >= 60 and score <= 69):
        char = 'C'
    elif(score >= 50 and score <= 59):
        char = 'D'
    else:
        char = 'E'
    return char

def count_grade(char , Total):
    i = 0
    number = 0
    while(i < len(Total)):
        score = Total[i].get_score()
        if(char == 'A' and score >= 80):
            number = number + 1
        elif(char == 'B' and score >= 70 and score <= 79):
            number = number + 1
        elif(char == 'C' and score >= 60 and score <= 69):
            number = number + 1
        elif(char == 'D' and score >= 50 and score <= 59):
            number = number + 1
        elif(char == 'F' and score <= 49):
            number = number + 1
        i = i+1
       
    return number

def show_allGtade(Total):

    for i in Total:
        i.display()
        print(find_grade(i))
        print()


setup()

[LAB8] BANNER V#JAVA

public class Banner {
 private String word;
 private String symbol;

 public Banner(String word, String symbol) {
  this.word = word;
  this.symbol = symbol;
 }

 public void printWord() {
  String[] A = { "A", "  #  ", " # # ", "#   #", "#####", "#   #" };
  String[] C = { "C", "#####", "#    ", "#    ", "#    ", "#####" };
  String[] E = { "E", "#####", "#    ", "#### ", "#    ", "#####" };
  String[] blank = { " ", "  ", "  ", "  ", "  ", "  " };
  String[][] character = { A, C, E, blank };
  this.changesymbol(character);
  char[] wordArray = this.word.toCharArray();
  for (int row = 1; row <= 5; row++) {
   for (int i = 0; i < this.word.length(); i++) {
    for (int j = 0; j < character.length; j++) {
     char checkChar = character[j][0].charAt(0);
     if (wordArray[i] == checkChar) {
      System.out.print(character[j][row]+" ");
     }
    }
   }
   System.out.println();
  }
 }

 public void changesymbol(String[][] character) {
  for (int i = 0; i < character.length; i++) {
   for (int j = 1; j < character[i].length; j++) {
    String newSymbol = "";
    char[] wordArray = character[i][j].toCharArray();
    char checkSymbol = this.symbol.charAt(0);
    for (int k = 0; k < character[i][j].length(); k++) {
     if (wordArray[k] != checkSymbol && wordArray[k] != ' ') {
      newSymbol += this.symbol;
     } else {
      newSymbol += wordArray[k];
     }
    }
    character[i][j] = newSymbol;
 
   }
  }
 }

 public void set_symbol(String symbol) {
  this.symbol = symbol;
 }

 public static void main(String[] args) {
  Banner word = new Banner("AEC ACE ECE ACA", "#");
  word.printWord();
  System.out.println();
  word.set_symbol("*");
  word.printWord();
 }
}

[LAB8] AGE #JAVA

public class DataStudent
{
  private String name;
  private int sID;
  private int age;
  private int height;
  private int weight;


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

  public String get_name()
  {
    return this.name;
  }

  public int get_age()
  {
    return this.age;
  }

  public static void main(String[] args)
  {
    DataStudent[] s =
    {
      new DataStudent("Nop",20046,28.0,173,52),
      new DataStudent("Pee",20054,35.0,176,78),
      new DataStudent("Fern",20097,26.0,174,58),
    };
    //System.out.println(find_average(s));
    //System.out.println(find_age_less30(s));
    System.out.println(Sort_Age(s))
  }
 
 
  public static float find_average(DataStudent s)
  {
    float i = 0;
    float total = 0;
    float a = 0;
    while(i < s.length)
    {
      total = total + s[i].get_age() ;
      i = i + 1 ;
    }
    a = total / s.length ;
    return a ;
  }

  public static int find_age_less30(DataStudent[] s)
  {
    int c = 0;
    while(int i = 0 < student.length)
    {
      if(s[i].get_age() < 30)
      {
        c = c + 1;
      }
    }
    return c;
  }

  public static void Sort_Age(Student[] student)
  {
  for (int i = 1; i < student.length; i++)
  {
   Student currentStudent = student[i];
   int pos = i;
   while(pos > 0 && student[pos - 1].get_age() > currentStudent.get_age())
   {
    student[pos] = student[pos - 1];
    pos = pos - 1;
   }
   student[pos] = currentStudent;
  }
 }
}

[LAB8] BMI #JAVA

public class DataStudent
{
  private String name;
  private int sID;
  private int age;
  private int height;
  private int weight;


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

  public String get_name()
  {
    return this.name;
  }

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

  public float get_height()
  {
    return this.height;
  }

  public static void main(String[] args)
  {
    DataStudent[] s =
    {
      new DataStudent("Nop",20046,28,173,52),
      new DataStudent("Pee",20054,35,176,78),
      new DataStudent("Fern",20097,26,174,58),
    };
 
    //display_bmi_more_25
    int i = 0;
    while(i < s.length)
    {
      if(find_BMI_more25(s[i]) > 25)
         {
           System.out.println();
           System.out.println(s[i].get_name());
           System.out.println(String.format("%.2f",find_BMI_more25(s[i])));
         }
      i = i + 1;
    }
  }

  public static float find_BMI_more25(DataStudent sign)
  {
    float bmi = sign.get_weight()/((sign.get_height()/100) * (sign.get_height()/100));
    return bmi ;
  }
}

[LAB8] Data Student #JAVA

public class DataStudent
{
  private String name;
  private int sID;
  private int age;
  private int height;
  private int weight;


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

  public void display()
  {
    System.out.println(this.name);
    System.out.println(this.sID);
    System.out.println(this.age);
    System.out.println(this.height);
    System.out.println(this.weight+"\n");
  }

  public static void main(String[] args)
  {
    DataStudent[] s =
    {
      new DataStudent("Nop",20046,28,173,52),
      new DataStudent("Pee",20054,35,176,67),
      new DataStudent("Fern",20097,26,174,58),
    };
 
      //Display_student
      int i = 0;
      while(i < s.length)
      {
        s[i].display();
        i = i + 1;
      }
    }
}