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

Lab08 : String to Text [Java]

public class Banner {
  private String text="";
  private char style='#';

  public Banner(String text,char style){
    this.text=text;
    this.style=style;
  }
  public void setStyle(char style){
   this.style=style; 
  }
  public void display(){

        String[] A={" ##   ","#  #  ","####  ","#  #  ","#  #  "};
        String[] E={ "####  ", "#     ", "####  ", "#     ", "####  "};
        String[] C={ "####  ", "#     ", "#     ", "#     ", "####  "};
        String[] S={ "####  ", "#     ", "####  ", "   #  ", "####  "};
        int j=0;
    while (j<5){
            int i=0;
          while (i<this.text.length()){
                if (this.text.charAt(i)=='A'){
                    A[j]=replace_one(A[j],'#',this.style);
                    System.out.print(A[j]);
    }
                if (this.text.charAt(i)=='E'){
                    E[j]=replace_one(E[j],'#',this.style);
                    System.out.print(E[j]);
    }
                if (this.text.charAt(i)=='C'){
                    C[j]=replace_one(C[j],'#',this.style);
                    System.out.print(C[j]);
    }
                if (this.text.charAt(i)=='S'){
                    S[j]=replace_one(S[j],'#',this.style);
                    System.out.print(S[j]);
    }
                i+=1;
        }
       System.out.println();
       j+=1;
    }
  }
  public String replace_one(String t,char s,char r){
   StringBuilder temp = new StringBuilder(t);
    for (int i=0;i<t.length();i++){
      if (t.charAt(i)=='#'){
       temp.setCharAt(i,r); 
      }
    }
    return temp.toString();
  }

  public static void main(String[] args){
  Banner B = new Banner("AEC",'x');
    B.display();
   B.setStyle('o');
     B.display();

  }
}

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

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

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...