Whitney Martinez 6 年之前
父節點
當前提交
f6f66e1a9b
共有 1 個檔案被更改,包括 4 行新增30 行删除
  1. 4
    30
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java

+ 4
- 30
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java 查看文件

@@ -9,6 +9,7 @@ import java.util.List;
9 9
 public class StringAssembler {
10 10
     Character ch;
11 11
     String str;
12
+    StringBuilder sb = new StringBuilder();
12 13
 
13 14
     public StringAssembler(Character delimeter) {
14 15
 
@@ -22,39 +23,12 @@ public class StringAssembler {
22 23
     }
23 24
 
24 25
     public StringAssembler append(String str) {
25
-
26
-        int counter = 0;
27
-        String st = "";
28
-        StringBuilder sb = new StringBuilder();
29
-        List<String> list = new ArrayList<String>();
30
-
31
-            if(str != null) {
32
-                list.add(str);
33
-            }
34
-        for (int i = 0; i < list.size() ; i++) {
35
-
36
-            sb.append(str);
37
-        }
38
-
39
-        st = sb.toString();
40
-
41
-        StringAssembler sA = new StringAssembler(st);
42
-
43
-        return sA;
44
-
45
-
26
+            sb.append(str).append(this.ch);
27
+            return this;
46 28
     }
47 29
 
48 30
     public String assemble() {
49 31
 
50
-        StringBuffer sb = new StringBuffer();
51
-        String r = "";
52
-
53
-
54
-        sb.append(ch);
55
-
56
-
57
-        r = sb.toString();
58
-        return r;
32
+        return sb.deleteCharAt(this.sb.length() -1).toString();
59 33
     }
60 34
 }