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

Lab 8 - JAVA

public class Letter {
    private String[] T={"######","  #   ","  #   ","  #   ","  #   ","  #   "};
    private String[] O={"######","#    #","#    #","#    #","#    #","######"};
    private String[] P={"######","#    #","######","#     ","#     ","#     "};
    private String[][] data={T,O,P};
    private String word;
    private char cha;
   
      public Letter(String word,char cha){
        this.word=word;
        this.cha=cha;
        this.data=data;
      }
     
      public void changcha(){
        int i=0;
        while(i<data.length){
            int j=0;
            while(j<data[0].length){
              data[i][j]=data[i][j].replace('#',cha);
            j+=1;
            }
        i+=1;
        }
      }
     
      public void display(){
        int i=0;
        while(i<6){
          int j=0;
          while(j<word.length()){
            if(word.charAt(j)=='T'){
                System.out.print(this.data[0][i]);
                System.out.print(" ");
            }else if(word.charAt(j)=='O'){
                System.out.print(this.data[1][i]);
                System.out.print(" ");
            }else if(word.charAt(j)=='P'){
                System.out.print(this.data[2][i]);
                System.out.print(" ");
            }
          j+=1;
          }
        System.out.println("");
        i+=1;
        }
      }
     
     
   
    public static void main(String[] args) {
      //String[] word=;
      Letter a=new Letter("TOP",'@');
      a.changcha();
      a.display();
      //a.display();
    }
}
   

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

package fffff;

public class Student{
    private String name;
    private int id;
    private int age;
    private float weight;
    private float height;
    private float bmi;
   
    public Student(String name,int id,int age ,float weight,float height){
      this.name=name;
      this.id=id;
      this.age=age;
      this.weight=weight;
      this.height=height;
    }
   
    public void display(){
      System.out.print(" "+this.name);
      System.out.print("     "+this.id);
      System.out.print("      "+this.age);
      System.out.print("      "+this.weight);
      System.out.println("      "+this.height);
    }
    public float bmi_st(){
        bmi=cal_bmi(weight,height);
        this.bmi=bmi;
        return bmi;
    }
    public String get_name(){
        return this.name;
    }public int get_id(){
        return this.id;
    }public int get_age(){
        return this.age;
    }public float get_weight(){  
        return this.weight;
    }public float get_height(){
        return this.height;
    }public float get_bmi(){
        return this.bmi;
    }    
       
public static void main(String arg[]){
    Student[] std={new Student("top",91,21,80,178),
                   new Student("tape",32,32,50,175),
                   new Student("tar",55,18,30,175)};
    display(std);    
    std_bmi(std);
    int indexbmi=25;  
    int countbmi=bmi_morethan(std,indexbmi);
    System.out.println(countbmi);
    System.out.print(average_st(std));
   
    int indexage=30;
    int countage=age_lessthan(std,indexage);
    System.out.println(countage);
   
    float mini=minimum_weight(std);
    System.out.println(mini);
    int indexweight=50;
   
    int countweight=weight_lessthan(std,indexweight);
    System.out.println(countweight);
   
    displaylessthan(std,indexweight);  
}

public static void display(Student[] s){
    int i=0;
    while(i<s.length){
        s[i].display();
        i+=1;
    }
}
public static void std_bmi(Student[] s){
    int i=0;
    while(i<s.length){
        s[i].bmi_st();
        i+=1;
    }
}
public static float cal_bmi(float w,float h){
    float bmi=0;
    h=h/100;
    bmi=w/(h*h);
    return bmi;
}
public static int bmi_morethan(Student[] s,int max){
    int i=0;
    int count=0;
    while(i<s.length){
        if(s[i].get_bmi()>max){
            s[i].display();
            count+=1;
        }
        i+=1;
    }
    return count;
}
public static int average_st(Student[] s){
    int i=0;
    int sum=0;
    while(i<s.length){
        sum=sum+s[i].get_age();
        i+=1;
    }
    sum=sum/s.length;
    return sum;
}  
public static int age_lessthan(Student[]s,int max){
    int i=0;
    int count=0;
    while(i<s.length){
        if(s[i].get_age()<max){
            count+=1;
        }
        i+=1;
    }
    return count;
}
public static float minimum_weight(Student[] s){
    int i=1;
    float mini=s[0].get_weight();
    while(i<s.length){
        if(s[i].get_weight()<mini){
            mini=s[i].get_weight();
        }
        i+=1;
    }
    return mini;
}
public static int weight_lessthan(Student[] s,int max){
    int i=0;
    int count=0;
    while(i<s.length){
        if(s[i].get_weight()<max){
            count+=1;
        }
        i+=1;
    }
    return count;
}
public static void displaylessthan(Student[] s,int max){
    int i=0;
    while(i<s.length){
        if(s[i].get_weight()<max){
            s[i].display();
        }
    i+=1;
    }
}}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น