วันเสาร์ที่ 14 พฤศจิกายน พ.ศ. 2558

Lab8_Find_>_25


public class Student {
 private String name;
 private int idNO;
 private int age;
 private int weight;
 private int height;

 public Student(String name,int idNO,int age,int weight,int height){
 this.name = name;
 this.idNO = idNO;
 this.age = age;
 this.height = height;
 this.weight = weight;
}
public int get_age(){
return this.age;
}

public void display(){
 System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
  Student[] a =  {new Student("James",58001,13,177,90),
        new Student("Jane",58002,15,140,60),
        new Student("John",58003,17,156,54),
        new Student("Jonas",58004,20,188,70)};
 int i =0;
    while(i<a.length){
     a[i].display();
     System.out.println("this "+find_more_25(a,i)+" older than 25");
     i=i+1;
    }
 }

public static String find_more_25(Student[] a,int i){
String n="";
if(a[i].get_age()>25){
n=("one");
}else{
    n=("one not");
}
return n ;
}
}

Lab8_Avg_age


public class Student {
 private String name;
 private int idNO;
 private int age;
 private int weight;
 private int height;

 public Student(String name,int idNO,int age,int weight,int height){
 this.name = name;
 this.idNO = idNO;
 this.age = age;
 this.height = height;
 this.weight = weight;
}
public int get_age(){
return this.age;
}

public void display(){
 System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
  Student[] a =  {new Student("James",58001,13,177,90),
        new Student("Jane",58002,15,140,60),
        new Student("John",58003,17,156,54),
        new Student("Jonas",58004,20,188,70)};
 int i =0;
    while(i<a.length){
     a[i].display();
     i=i+1;
    }
    System.out.print("the avg. age is "+cal_avg_age(a));
 }
public static float cal_avg_age(Student[] a){
int i = 0;
int sums = 0 ;
float avg = 0 ;
while(i<a.length){
int age=a[i].get_age();
   sums = sums+age;
   avg = sums/a.length;
   i=i+1;  
}
return avg;
}
}

Lab8_Student_Find_More_BMI(25)


public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;

public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}

public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);

}

public static void main(String[] args){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
    System.out.println("this "+find_more_BMI(a,i)+" has > 25");
    i=i+1;
    }
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
     float w = a[i].get_weight();
     float h = a[i].get_height();
     bmi=w/((h/100)*(h/100));

return bmi;
}
public static String find_more_BMI(Student[] a,int i){
  String n ="";
  if(cal_bmi(a,i)>25){
     n =("one");
}else{
     n=("one not");}
  return n;
}
}

วันศุกร์ที่ 13 พฤศจิกายน พ.ศ. 2558

Lab8_Student_BMI


public class Student {
private String name;
private int idNO;
private int age;
private float weight;
private float height;

public Student(String name,int idNO,int age,float height,float weight){
this.name = name;
this.idNO = idNO;
this.age = age;
this.height = height;
this.weight = weight;
}
public float get_height(){
return this.height;
}
public float get_weight(){
return this.weight;
}

public void display(){
System.out.println("Name :"+this.name+"ID NO :"+this.idNO+"Age : "+this.age+"Weight : "+this.weight+"Height : "+this.height);
}

public static void main(String[] args){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    System.out.println("BMI : "+String.format("%.2f",cal_bmi(a, i)));
    i=i+1;
    }
}
public static float cal_bmi(Student[] a,int i){
float bmi = 0;
     float w = a[i].get_weight();
     float h = a[i].get_height();
     bmi=w/((h/100)*(h/100));

return bmi;
}
}

Lab8_Student_Display


public class Student {
private String name;
private int idNO;
private int age;
private int weight;
private int height;

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

public void display(){
System.out.println("Name :"+this.name+" ID NO :"+this.idNO+" Age : "+this.age+" Weight : "+this.weight+" Height : "+this.height);
}

public static void main(String[] arg){
Student[] a =  {new Student("James",58001,13,177,90),
    new Student("Jane",58002,15,140,60),
    new Student("John",58003,17,156,54),
    new Student("Jonas",58004,20,188,70)};
int i =0;
    while(i<a.length){
    a[i].display();
    i=i+1;
    }
}
}

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

Lab7_Data_AGE

class student:
   def __init__(self,names,idno,ages,he ,we ):
      self.names = names
      self.idNo = idno
      self.age = ages
      self.weight = we
      self.height = he
   def display(self):
      print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
   def get_age(self):
      return self.age
   def get_names(self):
      return self.names
def setup():
    a= [student('James',58001,13,177,90),
        student('Jane',58002,35,140,60),
        student('John',58003,17,156,54),
        student('Jonas',58004,40,188,70)]
    i=0
    while(i<len(a)):
          a[i].display()
          print()
          i=i+1
    print('the avg of age is',cal_avgAge(a))
    findLess30(a)
def cal_avgAge(a):
      sums=0
      i=0
      while(i<len(a)):
         ages=a[i].get_age()
         sums=sums+ages
         avg=sums/len(a)
         i=i+1
      return avg
def findLess30(a):
   i=0
   n=0
   while(i<len(a)):
      ages=a[i].get_age()
      names=a[i].get_names()
      if(ages<30):
         n=n+1
         print(names,'is younger than 30')
      i=i+1
   print('there are ',n,'students < 30')
setup()

Lab7_Data_BMI

class student:
   def __init__(self,names,idno,ages,he ,we ):
      self.names = names
      self.idNo = idno
      self.age = ages
      self.weight = we
      self.height = he
   def display(self):
      print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
   def get_height(self):
      return self.height
   def get_weight(self):
      return self.weight
def setup():
    a= [student('James',58001,13,177,90),
        student('Jane',58002,15,140,60),
        student('John',58003,17,156,54),
        student('Jonas',58004,20,188,70)]
    i=0
    while(i<len(a)):
          a[i].display()
          print('BMI = %.2f'%cal_bmi(a,i))
          print('this ',find_more_BMI(a,i),'has BMI >25')
          print()
          i=i+1
def cal_bmi(a,i):
   while(i<len(a)):
      n=0
      w = a[i].get_weight()
      h = a[i].get_height()
      bmi=w/(h/100)**2
      return bmi
def find_more_BMI(a,i):
   n=0
   if(cal_bmi(a,i)>25):
      n='one'
   else:
      n='one not'
   return n
   
setup()

Lab7_Display_Student_Data

class student:
   def __init__(self,names,idno,ages,we ,he ):
      self.names = names
      self.idNo = idno
      self.age = ages
      self.weight = we
      self.height = he
   def display(self):
      print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)

def setup():
     j1=student('James',58001,13,177,50)
     j2=student('Jane',58002,15,140,60)
     j3=student('John',58003,17,156,54)
     j4=student('Jonas',58004,20,188,70)
     a=[j1,j2,j3,j4]
     i=0
     while(i<len(a)):
           a[i].display()
           i=i+1
setup()

Lab6_Matrix_%and*

def setup():
   m1=[[1,2,3],[4,5,6]]
   m2=[[4,2,6],[14,19,15]]
   SubtractMatrix(m1,m2)
   MultipleMatrix(m1,m2)
def SubtractMatrix(a,b):
   print('SubtractMatrix')
   i=0
   while(i<len(a)):
      j=0
      while(j<len(a[i])):
            print(a[i][j]-b[i][j]," ",end = "")
            j=j+1
      i=i+1
      print("")
def MultipleMatrix(a,b):
   print('MultipleMatrix')
   i=0
   while(i<len(a)):
      j=0
      while(j<len(a[i])):
            print(a[i][j]*b[i][j]," ",end = "")
            j=j+1
      i=i+1
      print("")
setup()

Lab6_Matrix_showAndAdd

def setup():
   m1=[[1,2,3],[4,5,6]]
   m2=[[7,8,9],[10,11,12]]
   addMatrix(m1,m2)
 
def showMatrix(a):
   i=0
   while(i<len(a)):
      print(a[i])
      i=i+1
def addMatrix(a,b):
   i=0
   while(i<len(a)):
      j=0
      while(j<len(a[i])):
            print(a[i][j]+b[i][j]," ",end = "")
            j=j+1
      i=i+1
      print("")
setup()

Lab6_Find_maximum_chair_index

def setup():
   floor1=[14,25,18,38]#building[0][0-3]
   floor2=[34,21,48,24]#building[1][0-3]
   floor3=[48,29,12,48]#building[2][0-3]
   building = [floor1,floor2,floor3]
   findRoomWithMaxChair(building)
def findRoomWithMaxChair(a):
   i=0
   j=0
   maximum=0
   while(j<len(a)):
      while(i<len(a[j])):
         if(maximum<a[j][i]):
            maximum=a[j][i]
         i=i+1
      i=0
      j=j+1
   i=0
   j=0
   while(j<len(a)):
      while(i<len(a[j])):
          if(maximum == a[j][i]):
               print('floor index:',j,',room index:',i)
          i=i+1
      i=0
      j=j+1
setup()
   

Lab6_findIndexofMaximumChair

def setup():
   floor1=[14,25,18,38]#building[0][0-3]
   floor2=[34,21,28,24]#building[1][0-3]
   floor3=[48,29,12,48]#building[2][0-3]
   building = [floor1,floor2,floor3]
   print('maximum chairs index is ',maxFloor(building))
def maxFloor(a):
   i=0#chair
   j=0#floor
   j2=0
   maximum=0
   while(j<len(a)):
      while(i<len(a[j])):
         if(maximum<a[j][i]):
            maximum=a[j][i]
            j2=j
         i=i+1
      i=0
      j=j+1
   return j2
setup()
     

Lab6_FindChairsInBuilding

def setup():
   floor1=[14,25,18,38]#building[0][0-3]
   floor2=[34,21,28,24]#building[1][0-3]
   floor3=[24,29,12,48]#building[2][0-3]
   building = [floor1,floor2,floor3]
   print('there are ',sumChair(building),' chairs in the building')
def sumChair(a):
   i=0#chair
   j=0#floor
   sums=0
   while(j<len(a)):
      while(i<len(a[j])):
         sums=sums+a[j][i]
         i=i+1
      i=0
      j=j+1
   return sums
setup()

Lab6_DataAndWeight

def setup():
   names=["Jack",'John','James','Jane']
   idNo=['5801','5802','5803','5804']
   age=[18,32,15,41]
   weight=[40,69,72,49]
   height=[150,162,170,159]
   listthedata(names,idNo,age,weight,height)
   print('the minimum weight is ',findminW(names,weight))
   print('there are ',findMinWeiNumber(names,weight),'students < 50')
def listthedata(names,idNo,age,weight,height):
    i=0
    while(i<len(names)):
         if(weight[i]<50):
            print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
            print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
            print()
         i=i+1
def cal_bmi(i,weight,height):
   bmi=(weight[i])/((height[i]/100)**2)
   return bmi
def findminW(names,weight):
   i=0
   minimum=weight[0]
   while(i<len(weight)):
      if(minimum>weight[i]):
           minimum=weight[i]
      i=i+1
   return minimum
def findMinWeiNumber(names,weight):
   i=0
   sums=0
   while(i<len(names)):
      if(weight[i]<50):
         sums=sums+1
      i=i+1
   return sums
setup()

Lab6_DataAndAge

def setup():
   names=["Jack",'John','James','Jane']
   idNo=['5801','5802','5803','5804']
   age=[18,32,15,41]
   weight=[60,99,72,50]
   height=[150,162,170,159]
   listthedata(names,idNo,age,weight,height)
   print(lessage30(names,age),'student < 30')
   print('the avg age is',find_avgAge(names,age))
   sortByAge(names,age)
 
def listthedata(names,idNo,age,weight,height):
    i=0
    while(i<len(names)):
         print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
         print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
         print()
         i=i+1
def sortByAge(names,age):
   j=1
   while(j<len(age)):
      n=age[j]
      i=j-1
      while(i >= 0) and (age[i] > n):
         age[i+1]=age[i]
         i=i-1
      age[i+1] = n
      j=j+1
   print(age)
       
def cal_bmi(i,weight,height):
   bmi=(weight[i])/((height[i]/100)**2)
   return bmi
def lessage30(names,age):
   i=0
   sums=0
   while(i<len(names)):
      if(age[i]<30):
         sums=sums+1
      i=i+1
   return sums
def find_avgAge(names,age):
   i=0
   sums=0
   while(i<len(names)):
      sums=sums+age[i]
      i=i+1
   avg=sums/len(names)
   return avg
setup()