浏览代码

completed JavaStringCheese Lab

父节点
当前提交
95844bdb92
共有 5 个文件被更改,包括 41 次插入19 次删除
  1. 二进制
      StringParser.class
  2. 38
    10
      StringParser.java
  3. 二进制
      StringParserTest.class
  4. 2
    0
      StringParserTest.java
  5. 1
    9
      package.bluej

二进制
StringParser.class 查看文件


+ 38
- 10
StringParser.java 查看文件

@@ -1,3 +1,4 @@
1
+package JavaStringCheese;
1 2
 
2 3
 /**
3 4
  * An introduction to Strings and String methods.
@@ -15,7 +16,9 @@ public class StringParser
15 16
      */
16 17
     public static String upperCaseString(String s)
17 18
     {
18
-        return null;
19
+        String upperCase = s;
20
+        return upperCase.toUpperCase();
21
+
19 22
     }
20 23
 
21 24
     /**
@@ -26,7 +29,8 @@ public class StringParser
26 29
      * @return String
27 30
      */
28 31
     public static String lowerCaseString(String s) {
29
-        return null;
32
+        String lowerCase = s;
33
+        return lowerCase.toLowerCase();
30 34
     }
31 35
 
32 36
     /**
@@ -37,7 +41,8 @@ public class StringParser
37 41
      * @return String
38 42
      */
39 43
     public static Character getFirstCharacter(String s) {
40
-        return null;
44
+        String char1 = s;
45
+        return char1.charAt(0);
41 46
     }
42 47
 
43 48
     /**
@@ -49,7 +54,8 @@ public class StringParser
49 54
      * @return String
50 55
      */
51 56
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
57
+        String charN = s;
58
+        return charN.charAt(n);
53 59
     }
54 60
 
55 61
     /**
@@ -60,7 +66,9 @@ public class StringParser
60 66
      * @return String
61 67
      */
62 68
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
69
+        String string1 = s;
70
+
71
+        return string1.substring(0,1).toUpperCase() + string1.substring(1);
64 72
     }
65 73
 
66 74
     /**
@@ -72,7 +80,14 @@ public class StringParser
72 80
      * @return String
73 81
      */
74 82
     public static String camelCaseString(String s) {
75
-        return null;
83
+        String string1 = s;
84
+        int space = string1.indexOf(" ");
85
+        String string2 = string1.substring(0,1).toUpperCase();
86
+        String string3 = string1.substring(1, space).toLowerCase();
87
+        String string4 = string1.substring(space+1, space+2).toUpperCase();
88
+        String string5 = string1.substring(space+2).toLowerCase();
89
+
90
+        return string2 + string3 + string4 + string5;
76 91
     }
77 92
 
78 93
     /**
@@ -84,7 +99,15 @@ public class StringParser
84 99
      * @return String
85 100
      */
86 101
     public static String snakeCaseString(String s) {
87
-        return null;
102
+        String string1 = s;
103
+        int space = string1.indexOf(" ");
104
+        String string2 = string1.substring(0,space).toLowerCase();
105
+        String string3 = string1.substring(space, space+1);
106
+        String string4 = "_";
107
+        String string5 = string1.substring(space+1).toLowerCase();
108
+        
109
+
110
+        return string2 + string4 + string5;
88 111
     }
89 112
 
90 113
     /**
@@ -95,7 +118,8 @@ public class StringParser
95 118
      * @return String
96 119
      */
97 120
     public static Integer getLength(String s) {
98
-        return null;
121
+        String string1 = s;
122
+        return s.length();
99 123
     }
100 124
 
101 125
     /**
@@ -109,7 +133,9 @@ public class StringParser
109 133
      * @return String
110 134
      */
111 135
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
136
+        String string1 = s1;
137
+        String string2 = s2;
138
+        return string1.equals(string2);
113 139
     }
114 140
 
115 141
     /**
@@ -123,6 +149,8 @@ public class StringParser
123 149
      * @return String
124 150
      */
125 151
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
152
+        String string1 = s1;
153
+        String string2 = s2;
154
+        return string1.equalsIgnoreCase(string2);
127 155
     }
128 156
 }

二进制
StringParserTest.class 查看文件


+ 2
- 0
StringParserTest.java 查看文件

@@ -1,3 +1,5 @@
1
+package JavaStringCheese;
2
+
1 3
 import org.junit.Test;
2 4
 
3 5
 import static org.junit.Assert.*;

+ 1
- 9
package.bluej 查看文件

@@ -1,11 +1,4 @@
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 2
 objectbench.height=164
10 3
 objectbench.width=776
11 4
 package.divider.horizontal=0.6
@@ -16,11 +9,10 @@ package.editor.x=0
16 9
 package.editor.y=23
17 10
 package.frame.height=600
18 11
 package.frame.width=800
19
-package.numDependencies=1
12
+package.numDependencies=0
20 13
 package.numTargets=2
21 14
 package.showExtends=true
22 15
 package.showUses=true
23
-project.charset=UTF-8
24 16
 readme.height=58
25 17
 readme.name=@README
26 18
 readme.width=47