瀏覽代碼

late but better than never.

Jennifer Tinkler 6 年之前
父節點
當前提交
328f4db8dd
共有 5 個檔案被更改,包括 98 行新增46 行删除
  1. 二進制
      .DS_Store
  2. 二進制
      StringParser.class
  3. 1
    3
      StringParser.ctxt
  4. 81
    24
      StringParser.java
  5. 16
    19
      package.bluej

二進制
.DS_Store 查看文件


二進制
StringParser.class 查看文件


+ 1
- 3
StringParser.ctxt 查看文件

@@ -1,9 +1,7 @@
1 1
 #BlueJ class context
2 2
 comment0.target=StringParser
3
-comment0.text=\n\ An\ introduction\ to\ Strings\ and\ String\ methods.\n\n\ @author\ Wilhem\ Alcivar\n
4 3
 comment1.params=s
5 4
 comment1.target=java.lang.String\ upperCaseString(java.lang.String)
6
-comment1.text=\n\ Takes\ a\ String\ and\ returns\ that\ String\ with\ all\ characters\ uppercased.\n\ E.G.\ cat\ would\ become\ CAT.\ dOnUt\ would\ become\ DONUT.\n\n\ @param\ s\n\ @return\ String\n
7 5
 comment10.params=s1\ s2
8 6
 comment10.target=java.lang.Boolean\ isEqualIgnoreCase(java.lang.String,\ java.lang.String)
9 7
 comment10.text=\n\ Takes\ in\ two\ strings\ and\ returns\ true\ if\ they\ are\ equal\n\ E.G.\ example\ and\ shelf\ would\ return\ false.\ \n\ cat\ and\ CaT\ would\ return\ true.\ \n\ Dog\ and\ Dog\ would\ return\ true\n\n\ @param\ s1\n\ @param\ s2\n\ @return\ String\n
@@ -12,7 +10,7 @@ comment2.target=java.lang.String\ lowerCaseString(java.lang.String)
12 10
 comment2.text=\n\ Takes\ a\ String\ and\ returns\ that\ String\ with\ all\ characters\ lowercased.\n\ E.G.\ MOUSE\ would\ become\ mouse.\ dOnUt\ would\ become\ donut.\n\n\ @param\ s\n\ @return\ String\n
13 11
 comment3.params=s
14 12
 comment3.target=java.lang.Character\ getFirstCharacter(java.lang.String)
15
-comment3.text=\n\ Takes\ a\ String\ and\ returns\ the\ first\ character\ of\ that\ string.\n\ E.G.\ cat\ would\ return\ c.\ Embark\ would\ return\ E.\n\n\ @param\ s\n\ @return\ String\n
13
+comment3.text=\n\ Takes\ a\ String\ and\ returns\ the\ first\ character\ of\ that\ string.\n\ E.G.\ cat\ would\ return\ c.\ Embark\ would\ return\ E.\n\n\ @param\ s\n\ @return\ String\n\ \n
16 14
 comment4.params=s\ n
17 15
 comment4.target=java.lang.Character\ getNthCharacter(java.lang.String,\ java.lang.Integer)
18 16
 comment4.text=\n\ Takes\ a\ String\ and\ returns\ the\ character\ at\ index\ n\ of\ that\ string.\n\ E.G.\ cat,\ 2\ would\ return\ t.\ Embark,\ 4\ would\ return\ r.\n\n\ @param\ s\n\ @param\ n\n\ @return\ String\n

+ 81
- 24
StringParser.java 查看文件

@@ -4,20 +4,30 @@
4 4
  *
5 5
  * @author Wilhem Alcivar
6 6
  */
7
+
8
+import java.util.*;
9
+
10
+
7 11
 public class StringParser
8 12
 {
9
-    /**
10
-     * Takes a String and returns that String with all characters uppercased.
11
-     * E.G. cat would become CAT. dOnUt would become DONUT.
12
-     *
13
-     * @param s
14
-     * @return String
15
-     */
16
-    public static String upperCaseString(String s)
17
-    {
18
-        return null;
13
+    public static String upperCaseString(String s) {
14
+        
15
+        return  s.toUpperCase(); 
16
+      
17
+        
18
+        
19
+        
20
+        
19 21
     }
20
-
22
+      
23
+      
24
+        
25
+       
26
+  
27
+    
28
+    
29
+        
30
+        
21 31
     /**
22 32
      * Takes a String and returns that String with all characters lowercased.
23 33
      * E.G. MOUSE would become mouse. dOnUt would become donut.
@@ -26,20 +36,29 @@ public class StringParser
26 36
      * @return String
27 37
      */
28 38
     public static String lowerCaseString(String s) {
29
-        return null;
39
+       
40
+       return s.toLowerCase();
41
+       
42
+     
30 43
     }
31
-
44
+    
45
+    
32 46
     /**
33 47
      * Takes a String and returns the first character of that string.
34 48
      * E.G. cat would return c. Embark would return E.
35 49
      *
36 50
      * @param s
37 51
      * @return String
52
+     * 
38 53
      */
54
+    
39 55
     public static Character getFirstCharacter(String s) {
40
-        return null;
41
-    }
42
-
56
+       
57
+    return s.charAt(0);
58
+  
59
+    
60
+    
61
+}
43 62
     /**
44 63
      * Takes a String and returns the character at index n of that string.
45 64
      * E.G. cat, 2 would return t. Embark, 4 would return r.
@@ -49,7 +68,9 @@ public class StringParser
49 68
      * @return String
50 69
      */
51 70
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
71
+        
72
+         
73
+        return s.charAt(n);
53 74
     }
54 75
 
55 76
     /**
@@ -60,7 +81,15 @@ public class StringParser
60 81
      * @return String
61 82
      */
62 83
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
84
+      
85
+        
86
+        //t = Character.toUpperCase(t.charAt(0)) + t.substring(1);
87
+        
88
+        //System.out.println(t);
89
+         return (s.substring (0,1)).toUpperCase() + s.substring(1);
90
+       
91
+        
92
+       
64 93
     }
65 94
 
66 95
     /**
@@ -72,7 +101,22 @@ public class StringParser
72 101
      * @return String
73 102
      */
74 103
     public static String camelCaseString(String s) {
75
-        return null;
104
+   String [] words = s.split(" ");
105
+   
106
+   String t = "";
107
+   int i; 
108
+   //String firstWord;
109
+    for ( i = 0;  i < words.length; i ++) { 
110
+        
111
+        t += words[i].substring (0,1).toUpperCase() + words[i].substring(1).toLowerCase() ;
112
+    
113
+     //t.join(firstWord); 
114
+    }
115
+     //String nextWord = words[1].substring (0,1).toUpperCase() + words[1].substring(1).toLowerCase();
116
+     
117
+     //String nextWord2 = words[2].substring (0,1).toUpperCase() + words[2].substring(1).toLowerCase();
118
+       return t;
119
+        
76 120
     }
77 121
 
78 122
     /**
@@ -84,8 +128,13 @@ public class StringParser
84 128
      * @return String
85 129
      */
86 130
     public static String snakeCaseString(String s) {
87
-        return null;
131
+        return s.replaceAll(" ", "_").toLowerCase();
132
+        
88 133
     }
134
+     
135
+   
136
+ 
137
+    
89 138
 
90 139
     /**
91 140
      * Takes a String and returns the length of that string
@@ -95,7 +144,7 @@ public class StringParser
95 144
      * @return String
96 145
      */
97 146
     public static Integer getLength(String s) {
98
-        return null;
147
+        return s.length(); 
99 148
     }
100 149
 
101 150
     /**
@@ -109,7 +158,10 @@ public class StringParser
109 158
      * @return String
110 159
      */
111 160
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
161
+        if (s1.equals(s2)) {
162
+            return true;
163
+        } else return false;
164
+
113 165
     }
114 166
 
115 167
     /**
@@ -123,6 +175,11 @@ public class StringParser
123 175
      * @return String
124 176
      */
125 177
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
127
-    }
178
+     if   (s1.equalsIgnoreCase(s2)){
179
+         
180
+              return true;
181
+         
182
+            } 
183
+            else return false;
184
+        }
128 185
 }

+ 16
- 19
package.bluej 查看文件

@@ -1,22 +1,19 @@
1 1
 #BlueJ package file
2
-dependency1.from=StringParserTest
3
-dependency1.to=StringParser
4
-dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=455
8
-editor.fx.0.y=51
9
-objectbench.height=164
10
-objectbench.width=776
2
+editor.fx.0.height=598
3
+editor.fx.0.width=687
4
+editor.fx.0.x=35
5
+editor.fx.0.y=23
6
+objectbench.height=101
7
+objectbench.width=886
11 8
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6845018450184502
13
-package.editor.height=364
14
-package.editor.width=674
15
-package.editor.x=0
16
-package.editor.y=23
17
-package.frame.height=600
18
-package.frame.width=800
19
-package.numDependencies=1
9
+package.divider.vertical=0.788235294117647
10
+package.editor.height=395
11
+package.editor.width=784
12
+package.editor.x=67
13
+package.editor.y=622
14
+package.frame.height=568
15
+package.frame.width=910
16
+package.numDependencies=0
20 17
 package.numTargets=2
21 18
 package.showExtends=true
22 19
 package.showUses=true
@@ -38,5 +35,5 @@ target2.name=StringParserTest
38 35
 target2.showInterface=false
39 36
 target2.type=UnitTestTargetJunit4
40 37
 target2.width=130
41
-target2.x=140
42
-target2.y=40
38
+target2.x=210
39
+target2.y=80