Computer Fundamental
วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
วันอังคารที่ 1 ธันวาคม พ.ศ. 2558
Display each student record JAVA
public class Students {
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Students(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 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();
}
public static void main(String[] args) {
Students a = new Students ("AAA", 11111, 20, 60, 165);
Students b = new Students ("BBB", 22222, 25, 65, 170);
Students c = new Students ("CCC", 33333, 15, 55, 160);
Students d = new Students ("DDD", 44444, 19, 50, 155);
Students[] data = {a, b, c, d};
display(data);
}
public static void display(Students[] data){
int i = 0;
while(i < data.length){
data[i].display();
i = i + 1 ;
}
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Students(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 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();
}
public static void main(String[] args) {
Students a = new Students ("AAA", 11111, 20, 60, 165);
Students b = new Students ("BBB", 22222, 25, 65, 170);
Students c = new Students ("CCC", 33333, 15, 55, 160);
Students d = new Students ("DDD", 44444, 19, 50, 155);
Students[] data = {a, b, c, d};
display(data);
}
public static void display(Students[] data){
int i = 0;
while(i < data.length){
data[i].display();
i = i + 1 ;
}
}
}
วันเสาร์ที่ 28 พฤศจิกายน พ.ศ. 2558
วันพฤหัสบดีที่ 26 พฤศจิกายน พ.ศ. 2558
Create class Banner for printing a banner
class Abc:
def __init__(self,line1,line2,line3,line4,line5):
self.line1 = line1
self.line2 = line2
self.line3 = line3
self.line4 = line4
self.line5 = line5
def display_line1(self):
print(self.line1,end = "")
def display_line2(self):
print(self.line2,end = "")
def display_line3(self):
print(self.line3,end = "")
def display_line4(self):
print(self.line4,end = "")
def display_line5(self):
print(self.line5,end = "")
def get_line1(self):
return self.line1
def get_line2(self):
return self.line2
def get_line3(self):
return self.line3
def get_line4(self):
return self.line4
def get_line5(self):
return self.line5
def print_star_L1(self):
hash_to_star(self.line1)
def print_star_L2(self):
hash_to_star(self.line2)
def print_star_L3(self):
hash_to_star(self.line3)
def print_star_L4(self):
hash_to_star(self.line4)
def print_star_L5(self):
hash_to_star(self.line5)
def hash_to_star(a):
i = 0
while(i < len(a)):
if(a[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i += 1
def draw(group,word):
i = 0
while(i < 5):
k = 0
while(k < len(word)):
if(word[k] == "A"):
print_fn(group,i,0)
elif(word[k] == "B"):
print_fn(group,i,1)
elif(word[k] == "C"):
print_fn(group,i,2)
elif(word[k] == "D"):
print_fn(group,i,3)
k += 1
print()
i += 1
def print_fn(group,i,index):
if(i == 0):
group[index].print_star_L1()
elif(i == 1):
group[index].print_star_L2()
elif(i == 2):
group[index].print_star_L3()
elif(i == 3):
group[index].print_star_L4()
elif(i == 4):
group[index].print_star_L5()
def setup():
A = Abc(" ###### ",
" # # ",
" ###### ",
" # # ",
" # # " )
B = Abc(" ##### ",
" # # ",
" ##### ",
" # # ",
" ##### " )
C = Abc(" #### ",
" # ",
" # ",
" # ",
" #### " )
D = Abc(" ##### ",
" # #",
" # #",
" # #",
" ##### " )
group = [A,B,C,D]
word = input("")
draw(group,word)
setup()
def __init__(self,line1,line2,line3,line4,line5):
self.line1 = line1
self.line2 = line2
self.line3 = line3
self.line4 = line4
self.line5 = line5
def display_line1(self):
print(self.line1,end = "")
def display_line2(self):
print(self.line2,end = "")
def display_line3(self):
print(self.line3,end = "")
def display_line4(self):
print(self.line4,end = "")
def display_line5(self):
print(self.line5,end = "")
def get_line1(self):
return self.line1
def get_line2(self):
return self.line2
def get_line3(self):
return self.line3
def get_line4(self):
return self.line4
def get_line5(self):
return self.line5
def print_star_L1(self):
hash_to_star(self.line1)
def print_star_L2(self):
hash_to_star(self.line2)
def print_star_L3(self):
hash_to_star(self.line3)
def print_star_L4(self):
hash_to_star(self.line4)
def print_star_L5(self):
hash_to_star(self.line5)
def hash_to_star(a):
i = 0
while(i < len(a)):
if(a[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i += 1
def draw(group,word):
i = 0
while(i < 5):
k = 0
while(k < len(word)):
if(word[k] == "A"):
print_fn(group,i,0)
elif(word[k] == "B"):
print_fn(group,i,1)
elif(word[k] == "C"):
print_fn(group,i,2)
elif(word[k] == "D"):
print_fn(group,i,3)
k += 1
print()
i += 1
def print_fn(group,i,index):
if(i == 0):
group[index].print_star_L1()
elif(i == 1):
group[index].print_star_L2()
elif(i == 2):
group[index].print_star_L3()
elif(i == 3):
group[index].print_star_L4()
elif(i == 4):
group[index].print_star_L5()
def setup():
A = Abc(" ###### ",
" # # ",
" ###### ",
" # # ",
" # # " )
B = Abc(" ##### ",
" # # ",
" ##### ",
" # # ",
" ##### " )
C = Abc(" #### ",
" # ",
" # ",
" # ",
" #### " )
D = Abc(" ##### ",
" # #",
" # #",
" # #",
" ##### " )
group = [A,B,C,D]
word = input("")
draw(group,word)
setup()
วันพุธที่ 25 พฤศจิกายน พ.ศ. 2558
rasbery
class Student:
def __init__(self,name,ID,score):
self.name=name
self.ID=ID
self.score=score
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_score(self):
return self.score
def set_score(self,s):
return self.s
def Display(self):
print("Name",self.name)
print("ID",self.ID)
print("Score",self.score)
def setup():
std=[Student("AA",11111,55),Student("BB",22222,80),Student("CC",33333,100),
Student("DD",44444,70),Student("DD",55555,60)]
x=std[0]
grade(std)
print("=-----------------------------------------------=")
print("Grade =",findgrade(x))
x.Display()
countgrade(std)
print("++++++++++++++++++++++++++++++++++++++++++++++++")
showallgrade(std)
def findgrade(y):
grade=""
if(y.get_score()<50):
grade="F"
if(y.get_score()>=50 and y.get_score()<60):
grade="D"
if(y.get_score()>=60 and y.get_score()<70):
grade="C"
if(y.get_score()>=70 and y.get_score()<80):
grade="B"
if(y.get_score()>=80 and y.get_score()<=100):
grade="A"
return grade
def showallgrade(y):
i=0
grade=""
while(i<len(y)):
grade=""
if(y[i].get_score() < 50 and y[i].get_score() >= 0):
grade="F"
elif(y[i].get_score()>=50 and y[i].get_score()<60):
grade="D"
elif(y[i].get_score()>=60 and y[i].get_score()<70):
grade="C"
elif(y[i].get_score()>=70 and y[i].get_score()<80):
grade="B"
elif(y[i].get_score()>=80 and y[i].get_score()<=100):
grade="A"
y[i].Display()
print("Grade=",grade)
print()
i=i+1
def countgrade(std):
i=0
count=0
while(i<len(std)):
if(findgrade(std[i])=="A"):
count=count+1
i=i+1
print("count of A=",count)
def grade(y):
i=0
while(i<len(y)):
y[i].Display()
print()
i=i+1
print()
setup()
def __init__(self,name,ID,score):
self.name=name
self.ID=ID
self.score=score
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_score(self):
return self.score
def set_score(self,s):
return self.s
def Display(self):
print("Name",self.name)
print("ID",self.ID)
print("Score",self.score)
def setup():
std=[Student("AA",11111,55),Student("BB",22222,80),Student("CC",33333,100),
Student("DD",44444,70),Student("DD",55555,60)]
x=std[0]
grade(std)
print("=-----------------------------------------------=")
print("Grade =",findgrade(x))
x.Display()
countgrade(std)
print("++++++++++++++++++++++++++++++++++++++++++++++++")
showallgrade(std)
def findgrade(y):
grade=""
if(y.get_score()<50):
grade="F"
if(y.get_score()>=50 and y.get_score()<60):
grade="D"
if(y.get_score()>=60 and y.get_score()<70):
grade="C"
if(y.get_score()>=70 and y.get_score()<80):
grade="B"
if(y.get_score()>=80 and y.get_score()<=100):
grade="A"
return grade
def showallgrade(y):
i=0
grade=""
while(i<len(y)):
grade=""
if(y[i].get_score() < 50 and y[i].get_score() >= 0):
grade="F"
elif(y[i].get_score()>=50 and y[i].get_score()<60):
grade="D"
elif(y[i].get_score()>=60 and y[i].get_score()<70):
grade="C"
elif(y[i].get_score()>=70 and y[i].get_score()<80):
grade="B"
elif(y[i].get_score()>=80 and y[i].get_score()<=100):
grade="A"
y[i].Display()
print("Grade=",grade)
print()
i=i+1
def countgrade(std):
i=0
count=0
while(i<len(std)):
if(findgrade(std[i])=="A"):
count=count+1
i=i+1
print("count of A=",count)
def grade(y):
i=0
while(i<len(y)):
y[i].Display()
print()
i=i+1
print()
setup()
วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558
Display student records with weight < 50
class Student:
def __init__(self,name,ID,age,weight,height):
self.name = name
self.ID = ID
self.age = age
self.weight = weight
self.height = height
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def display(self):
print('Name',self.name)
print('ID',self.ID)
print('Ages',self.age)
print("weight",self.weight)
print("height",self.height)
print()
def setup():
std = [Student('AAA',54321,20,45,145),
Student('BBB',52345,18,50,155),
Student('CCC',55123,25,45,160),
Student('DDD',55233,30,55,170),
Student('EEE',55555,10,30,120)]
count_weight(std)
def count_weight(std):
i=0
count=0
while(i<len(std)):
if(std[i].get_weight()<50):
std[i].display()
i=i+1
setup()
def __init__(self,name,ID,age,weight,height):
self.name = name
self.ID = ID
self.age = age
self.weight = weight
self.height = height
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def display(self):
print('Name',self.name)
print('ID',self.ID)
print('Ages',self.age)
print("weight",self.weight)
print("height",self.height)
print()
def setup():
std = [Student('AAA',54321,20,45,145),
Student('BBB',52345,18,50,155),
Student('CCC',55123,25,45,160),
Student('DDD',55233,30,55,170),
Student('EEE',55555,10,30,120)]
count_weight(std)
def count_weight(std):
i=0
count=0
while(i<len(std)):
if(std[i].get_weight()<50):
std[i].display()
i=i+1
setup()
Find/count number of students with weight < 50
class Student:
def __init__(self,name,ID,age,weight,height):
self.name = name
self.ID = ID
self.age = age
self.weight = weight
self.height = height
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def display(self):
print('Name',self.name)
print('ID',self.ID)
print('Ages',self.age)
print("weight",self.weight)
print("height",self.height)
print()
def setup():
std = [Student('AAA',54321,20,45,145),
Student('BBB',52345,18,50,155),
Student('CCC',55123,25,45,160),
Student('DDD',55233,30,55,170),
Student('EEE',55555,10,30,120)]
count_weight(std)
def count_weight(std):
i=0
count=0
while(i<len(std)):
if(std[i].get_weight()<50):
count=count+1
i=i+1
print(count)
setup()
def __init__(self,name,ID,age,weight,height):
self.name = name
self.ID = ID
self.age = age
self.weight = weight
self.height = height
def get_name(self):
return self.name
def get_ID(self):
return self.ID
def get_age(self):
return self.age
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def display(self):
print('Name',self.name)
print('ID',self.ID)
print('Ages',self.age)
print("weight",self.weight)
print("height",self.height)
print()
def setup():
std = [Student('AAA',54321,20,45,145),
Student('BBB',52345,18,50,155),
Student('CCC',55123,25,45,160),
Student('DDD',55233,30,55,170),
Student('EEE',55555,10,30,120)]
count_weight(std)
def count_weight(std):
i=0
count=0
while(i<len(std)):
if(std[i].get_weight()<50):
count=count+1
i=i+1
print(count)
setup()
สมัครสมาชิก:
บทความ (Atom)