PROGRAMMING FUNDAMENTAL
วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
[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()
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();
}
}
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;
}
}
}
{
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 ;
}
}
{
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;
}
}
}
{
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;
}
}
}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
[LAB7] BANNER LETTER #INCOMPLETE
class words:
def __init__(self,first,second,third,fourth,fifth):
self.first = first
self.second = second
self.third = third
self.fourth = fourth
self.fifth = fifth
def display_L_first(self):
print(self.first,end = "")
def display_L_second(self):
print(self.second,end = "")
def display_L_third(self):
print(self.third,end = "")
def display_L_fourth(self):
print(self.fourth,end = "")
def display_L_fifth(self):
print(self.fifth,end = "")
def get_word_L_first(self):
return self.first
def get_word_L_second(self):
return self.second
def get_word_L_third(self):
return self.third
def get_word_L_fourth(self):
return self.fourth
def get_word_L_fifth(self):
return self.fifth
def star_first(self):
hashtag_star(self.first)
def star_second(self):
hashtag_star(self.second)
def star_third(self):
hashtag_star(self.third)
def star_fourth(self):
hashtag_star(self.fourth)
def star_fifth(self):
hashtag_star(self.fifth)
def setup():
B = words("#####","# #","#####","# #","#####")
U = words("# #","# #","# #","# #"," ### ")
N = words("# #","## #","# # #","# ##","# #")
G = words(" ####","# ","# ###","# #","#####")
letter = [B,U,N,G]
word = input("")
draw_word(letter,word)
def draw_word(letter,word):
i_print = 0
while(i_print < 5):
i = 0
while(i < len(word)):
if(word[i] == "B"):
fun_print(letter,i_print,0)
elif(word[i] == "L"):
fun_print(letter,i_print,1)
elif(word[i] == "U"):
fun_print(letter,i_print,2)
elif(word[i] == "E"):
fun_print(letter,i_print,3)
i = i + 1
print()
i_print = i_print + 1
def hashtag_star(temp):
i = 0
while(i < len(temp)):
if(temp[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i = i + 1
def fun_print(letter,i_print,word_index):
if(i_print == 0):
letter[word_index].star_first()
elif(i_print == 1):
letter[word_index].star_second()
elif(i_print == 2):
letter[word_index].star_third()
elif(i_print == 3):
letter[word_index].star_fourth()
elif(i_print == 4):
letter[word_index].star_fifth()
setup()
def __init__(self,first,second,third,fourth,fifth):
self.first = first
self.second = second
self.third = third
self.fourth = fourth
self.fifth = fifth
def display_L_first(self):
print(self.first,end = "")
def display_L_second(self):
print(self.second,end = "")
def display_L_third(self):
print(self.third,end = "")
def display_L_fourth(self):
print(self.fourth,end = "")
def display_L_fifth(self):
print(self.fifth,end = "")
def get_word_L_first(self):
return self.first
def get_word_L_second(self):
return self.second
def get_word_L_third(self):
return self.third
def get_word_L_fourth(self):
return self.fourth
def get_word_L_fifth(self):
return self.fifth
def star_first(self):
hashtag_star(self.first)
def star_second(self):
hashtag_star(self.second)
def star_third(self):
hashtag_star(self.third)
def star_fourth(self):
hashtag_star(self.fourth)
def star_fifth(self):
hashtag_star(self.fifth)
def setup():
B = words("#####","# #","#####","# #","#####")
U = words("# #","# #","# #","# #"," ### ")
N = words("# #","## #","# # #","# ##","# #")
G = words(" ####","# ","# ###","# #","#####")
letter = [B,U,N,G]
word = input("")
draw_word(letter,word)
def draw_word(letter,word):
i_print = 0
while(i_print < 5):
i = 0
while(i < len(word)):
if(word[i] == "B"):
fun_print(letter,i_print,0)
elif(word[i] == "L"):
fun_print(letter,i_print,1)
elif(word[i] == "U"):
fun_print(letter,i_print,2)
elif(word[i] == "E"):
fun_print(letter,i_print,3)
i = i + 1
print()
i_print = i_print + 1
def hashtag_star(temp):
i = 0
while(i < len(temp)):
if(temp[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i = i + 1
def fun_print(letter,i_print,word_index):
if(i_print == 0):
letter[word_index].star_first()
elif(i_print == 1):
letter[word_index].star_second()
elif(i_print == 2):
letter[word_index].star_third()
elif(i_print == 3):
letter[word_index].star_fourth()
elif(i_print == 4):
letter[word_index].star_fifth()
setup()
สมัครสมาชิก:
บทความ (Atom)