public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public String get_name(){
return this.name;
}
public int get_weight(){
return this.weight;
}
public int get_high(){
return this.high;
}
public int get_age(){
return this.age;
}
public int get_ID(){
return this.ID;
}
public void set_name(String value){
this.name = value;
}
public void set_weight(int value){
this.weight = value;
}
public void set_high(int value){
this.high = value;
}
public void set_age(int value){
this.age = value;
}
public void set_ID(int value){
this.ID = value;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
sort_age(std);
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
}
public static void sort_age(Student[] std){
int index = 1 ;
while(index<std.length){
String value_name = std[index].get_name();
int value_weight = std[index].get_weight();
int value_high = std[index].get_high();
int value_age = std[index].get_age();
int value_ID = std[index].get_ID();
int pos = index ;
while(pos>0 &&std[pos - 1].get_age()>value_age){
std[pos].set_name(std[pos - 1].get_name());
std[pos].set_weight(std[pos - 1].get_weight());
std[pos].set_high(std[pos - 1].get_high());
std[pos].set_age(std[pos - 1].get_age());
std[pos].set_ID(std[pos - 1].get_ID());
pos = pos - 1;
}
if(pos != index){
std[pos].set_name(value_name);
std[pos].set_weight(value_weight);
std[pos].set_high(value_high);
std[pos].set_age(value_age);
std[pos].set_ID(value_ID);
}
index = index + 1;
}
}
}
วันจันทร์ที่ 16 พฤศจิกายน พ.ศ. 2558
Lab 8 - (Java) Find minimum weight of students
public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name ,int weight , int high , int age , int ID) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("The number of students that have weight less than 50 kg. is "+count_weight(std));
System.out.println( "The minimum weight is " +find_minimum_weight( std)+" kg. ");
}
public static int count_weight(Student[] std){
int index = 0 ;
int count = 0 ;
while(index<std.length){
if(std[index].get_weight()<50){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
public static int find_minimum_weight(Student[] std){
int index = 0;
int weight = 100;
while(index<std.length){
if(std[index].get_weight()<weight){
weight = std[index].get_weight();
}
index = index + 1;
}
return weight;
}
}
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name ,int weight , int high , int age , int ID) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("The number of students that have weight less than 50 kg. is "+count_weight(std));
System.out.println( "The minimum weight is " +find_minimum_weight( std)+" kg. ");
}
public static int count_weight(Student[] std){
int index = 0 ;
int count = 0 ;
while(index<std.length){
if(std[index].get_weight()<50){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
public static int find_minimum_weight(Student[] std){
int index = 0;
int weight = 100;
while(index<std.length){
if(std[index].get_weight()<weight){
weight = std[index].get_weight();
}
index = index + 1;
}
return weight;
}
}
วันจันทร์ที่ 9 พฤศจิกายน พ.ศ. 2558
Lab Class - Display Complex
class Complex:
def __init__(self,real,imagine=0):
self.real = real
self.imagine = imagine
def get_real(self):
return self.real
def get_imagine(self):
return self.imagine
def display_result(self):
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def setup():
a = Complex(2,-1)
b = Complex(2,-4)
a.display_result()
b.display_result()
setup()
def __init__(self,real,imagine=0):
self.real = real
self.imagine = imagine
def get_real(self):
return self.real
def get_imagine(self):
return self.imagine
def display_result(self):
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def setup():
a = Complex(2,-1)
b = Complex(2,-4)
a.display_result()
b.display_result()
setup()
Lab Class - Plus Complex
class Complex:
def __init__(self,real,imagine=0):
self.real = real
self.imagine = imagine
def get_real(self):
return self.real
def get_imagine(self):
return self.imagine
def display_result(self):
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def add_result(self,areal,aimagine):
self.real = self.real + areal
self.imagine = self.imagine + aimagine
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def setup():
a = Complex(2,-1)
b = [2,-4]
a.add_result(b[0],b[1])
setup()
def __init__(self,real,imagine=0):
self.real = real
self.imagine = imagine
def get_real(self):
return self.real
def get_imagine(self):
return self.imagine
def display_result(self):
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def add_result(self,areal,aimagine):
self.real = self.real + areal
self.imagine = self.imagine + aimagine
i = self.imagine
if i>0 :
print(self.real,end="+ ")
else :
print(self.real,end=" ")
print(self.imagine,end="i")
print()
def setup():
a = Complex(2,-1)
b = [2,-4]
a.add_result(b[0],b[1])
setup()
วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558
Lab Raspberry pi - Python Grade
class Student:
def __init__(self,name,idnum,score):
self.name = name
self.id = idnum
self.score = score
# get method
def get_id(self):
return self.idnum
def get_score(self):
return self.score
#set method
def set_score(self,value):
self.score = value
#display mathod
def display_info(self):
print("Name :", self.name)
print("ID :", self.id)
print("Score :", self.score)
def show_all(student):
i = 0
while i<len(student):
print("Grade",find_grade(student[i]))
student[i].display_info()
print()
i = i + 1
def show_grade(student):
i = 0
while i<len(student) :
print("Grade = ",find_grade(student[i]))
i = i+1
def count_grade(student):
i = 0
a = 0
b = 0
c = 0
d = 0
f = 0
while i<len(student) :
if find_grade(student[i]) == "A":
a = a + 1
elif find_grade(student[i]) == "B":
b = b + 1
elif find_grade(student[i]) == "C":
c = c + 1
elif find_grade(student[i]) == "D":
d = d + 1
elif find_grade(student[i]) == "F":
f = f + 1
i = i + 1
print("There is", a, "people have grade A")
print("There is", b, "people have grade B")
print("There is", c, "people have grade C")
print("There is", d, "people have grade D")
print("There is", f, "people have grade E")
def find_grade(student):
score = student.get_score()
if(score<50):
return "F"
elif(score<60):
return "D"
elif(score<70):
return "C"
elif(score<80):
return "B"
else :
return "A"
def setup():
student = [ Student("Nut",50001, 99),
Student("Fok",50002, 49),
Student("Gase",50003, 75),
Student("Pee", 50004, 68),
Student("Mind", 50005, 55)]
show_grade(student)
print()
count_grade(student)
print()
show_all(student)
setup()
def __init__(self,name,idnum,score):
self.name = name
self.id = idnum
self.score = score
# get method
def get_id(self):
return self.idnum
def get_score(self):
return self.score
#set method
def set_score(self,value):
self.score = value
#display mathod
def display_info(self):
print("Name :", self.name)
print("ID :", self.id)
print("Score :", self.score)
def show_all(student):
i = 0
while i<len(student):
print("Grade",find_grade(student[i]))
student[i].display_info()
print()
i = i + 1
def show_grade(student):
i = 0
while i<len(student) :
print("Grade = ",find_grade(student[i]))
i = i+1
def count_grade(student):
i = 0
a = 0
b = 0
c = 0
d = 0
f = 0
while i<len(student) :
if find_grade(student[i]) == "A":
a = a + 1
elif find_grade(student[i]) == "B":
b = b + 1
elif find_grade(student[i]) == "C":
c = c + 1
elif find_grade(student[i]) == "D":
d = d + 1
elif find_grade(student[i]) == "F":
f = f + 1
i = i + 1
print("There is", a, "people have grade A")
print("There is", b, "people have grade B")
print("There is", c, "people have grade C")
print("There is", d, "people have grade D")
print("There is", f, "people have grade E")
def find_grade(student):
score = student.get_score()
if(score<50):
return "F"
elif(score<60):
return "D"
elif(score<70):
return "C"
elif(score<80):
return "B"
else :
return "A"
def setup():
student = [ Student("Nut",50001, 99),
Student("Fok",50002, 49),
Student("Gase",50003, 75),
Student("Pee", 50004, 68),
Student("Mind", 50005, 55)]
show_grade(student)
print()
count_grade(student)
print()
show_all(student)
setup()
วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558
Lab 8 - (Java) Find/count number of students with age < 30
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 void display() {
System.out.println(this.name);
System.out.println(this.id);
System.out.println(this.age);
System.out.println(this.weight);
System.out.println(this.height);
}
public int get_age() {
return this.age;
}
public static void main(String[] args) {
Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
new Student("FlukeKnub", 00002, 17, 50, 179),
new Student("BasBomba", 00003, 20, 44, 188),
new Student("GaseKiki", 00004, 21, 67, 180),
new Student("PeeJa", 00005, 15, 88, 155)};
age_average(info);
}
public static void age_average(Student[] e) {
int count = 0;
int i = 0;
while (i < e.length) {
if (e[i].get_age() < 30) {
e[i].display();
System.out.println();
count = count + 1;
}
i = i + 1;
}
System.out.println(count);
}
}
Lab 8 - (Java) Find average age of students
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 void display() {
System.out.println(this.name);
System.out.println(this.id);
System.out.println(this.age);
System.out.println(this.weight);
System.out.println(this.height);
}
public int get_age() {
return this.age;
}
public static void main(String[] args) {
Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
new Student("FlukeKnub", 00002, 17, 50, 179),
new Student("BasBomba", 00003, 20, 44, 188),
new Student("GaseKiki", 00004, 21, 67, 180),
new Student("PeeJa", 00005, 15, 88, 155)};
age_average(info);
}
public static void age_average(Student[] e) {
int sum = 0;
int i = 0;
int average = 0;
while (i < e.length) {
sum = sum + e[i].get_age();
i = i + 1;
}
average = sum / e.length;
System.out.println(average);
}
}
Lab 8 - (Java) Find/count number of students with BMI > 25
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 void display() {
System.out.println(this.name);
System.out.println(this.id);
System.out.println(this.age);
System.out.println(this.weight);
System.out.println(this.height);
}
public float get_weight() {
return this.weight;
}
public float get_height() {
return this.height;
}
public static void main(String[] args) {
Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
new Student("FlukeKnub", 00002, 17, 50, 179),
new Student("BasBomba", 00003, 20, 44, 188),
new Student("GaseKiki", 00004, 21, 67, 180),
new Student("PeeJa", 00005, 15, 88, 155)};
bmi(info);
}
public static void bmi(Student[] e) {
int count = 0;
int i = 0;
float bmi = 0;
while (i < e.length) {
bmi = e[i].get_weight() / ((e[i].get_height() / 100) * (e[i].get_height() / 100));
if (bmi > 25) {
e[i].display();
System.out.println();
count = count + 1;
}
i = i + 1;
}
System.out.println(count);
}
}
Lab 8 - (Java) Find student BMI
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 float get_weight () {
return this.weight;
}
public float get_height () {
return this.height;
}
public static void main(String[] args) {
Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
new Student("FlukeKnub", 00002, 17, 50, 179),
new Student("BasBomba", 00003, 20, 44, 188),
new Student("GaseKiki", 00004, 21, 67, 180),
new Student("PeeJa", 00005, 15, 88, 155)};
bmi(info);
}
public static void bmi(Student[] e) {
int i = 0;
float bmi = 0;
while (i < e.length) {
bmi = e[i].get_weight()/((e[i].get_height ()/100)*(e[i].get_height ()/100));
System.out.println(bmi);
i = i + 1;
}
}
}
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 float get_weight () {
return this.weight;
}
public float get_height () {
return this.height;
}
public static void main(String[] args) {
Student[] info = {new Student("Bun Tun", 00001, 18, 68, 149),
new Student("FlukeKnub", 00002, 17, 50, 179),
new Student("BasBomba", 00003, 20, 44, 188),
new Student("GaseKiki", 00004, 21, 67, 180),
new Student("PeeJa", 00005, 15, 88, 155)};
bmi(info);
}
public static void bmi(Student[] e) {
int i = 0;
float bmi = 0;
while (i < e.length) {
bmi = e[i].get_weight()/((e[i].get_height ()/100)*(e[i].get_height ()/100));
System.out.println(bmi);
i = i + 1;
}
}
}
Lab 8 - (Java) Display each student record
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 void display() {
System.out.println( this.name );
System.out.println( this.id );
System.out.println( this.age );
System.out.println( this.weight );
System.out.println( this.height );
}
public static void main(String[] args) {
student[] info = { new student("Bun Tun", 00001, 18, 68, 149),
new student("FlukeKnub", 00002, 17, 50, 179),
new student("BasBomba", 00003, 20, 44, 188),
new student("GaseKiki", 00004, 21, 67, 180),
new student("PeeJa",00005, 15, 88, 155)};
display_info(info);
}
public static void display_info(student[] e) {
int i = 0;
while ( i < e.length) {
e[i].display();
System.out.println();
i = i + 1;
}
}
}
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 void display() {
System.out.println( this.name );
System.out.println( this.id );
System.out.println( this.age );
System.out.println( this.weight );
System.out.println( this.height );
}
public static void main(String[] args) {
student[] info = { new student("Bun Tun", 00001, 18, 68, 149),
new student("FlukeKnub", 00002, 17, 50, 179),
new student("BasBomba", 00003, 20, 44, 188),
new student("GaseKiki", 00004, 21, 67, 180),
new student("PeeJa",00005, 15, 88, 155)};
display_info(info);
}
public static void display_info(student[] e) {
int i = 0;
while ( i < e.length) {
e[i].display();
System.out.println();
i = i + 1;
}
}
}
สมัครสมาชิก:
บทความ (Atom)