Bläddra i källkod

lab completed

ThuyKhong 6 år sedan
förälder
incheckning
98a082e5d5
3 ändrade filer med 26 tillägg och 15 borttagningar
  1. Binär
      StringParser.class
  2. 22
    11
      StringParser.java
  3. 4
    4
      package.bluej

Binär
StringParser.class Visa fil


+ 22
- 11
StringParser.java Visa fil

@@ -15,7 +15,8 @@ public class StringParser
15 15
      */
16 16
     public static String upperCaseString(String s)
17 17
     {
18
-        return null;
18
+        String result = s.toUpperCase();
19
+        return result;
19 20
     }
20 21
 
21 22
     /**
@@ -26,7 +27,8 @@ public class StringParser
26 27
      * @return String
27 28
      */
28 29
     public static String lowerCaseString(String s) {
29
-        return null;
30
+        String result = s.toLowerCase();
31
+        return result;
30 32
     }
31 33
 
32 34
     /**
@@ -37,7 +39,7 @@ public class StringParser
37 39
      * @return String
38 40
      */
39 41
     public static Character getFirstCharacter(String s) {
40
-        return null;
42
+        return s.charAt(0);
41 43
     }
42 44
 
43 45
     /**
@@ -49,7 +51,7 @@ public class StringParser
49 51
      * @return String
50 52
      */
51 53
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
54
+        return s.charAt(n);
53 55
     }
54 56
 
55 57
     /**
@@ -60,7 +62,7 @@ public class StringParser
60 62
      * @return String
61 63
      */
62 64
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
65
+        return s.substring(0,1).toUpperCase() + s.substring(1);
64 66
     }
65 67
 
66 68
     /**
@@ -72,8 +74,14 @@ public class StringParser
72 74
      * @return String
73 75
      */
74 76
     public static String camelCaseString(String s) {
75
-        return null;
76
-    }
77
+        StringBuilder newStr = new StringBuilder();
78
+        String[] array = s.split(" ");
79
+            for (int i=0;i<array.length;i++){
80
+                s = array[i].substring(0, 1).toUpperCase() + array[i].substring(1).toLowerCase();
81
+                newStr.append(s);
82
+            }
83
+        return newStr.toString();
84
+}
77 85
 
78 86
     /**
79 87
      * Takes a String and returns that string with each character lowercased
@@ -84,7 +92,10 @@ public class StringParser
84 92
      * @return String
85 93
      */
86 94
     public static String snakeCaseString(String s) {
87
-        return null;
95
+        s = s.toLowerCase();
96
+        String[] array = s.split("\\ ");
97
+        String joined = String.join("_",array);
98
+        return joined;
88 99
     }
89 100
 
90 101
     /**
@@ -95,7 +106,7 @@ public class StringParser
95 106
      * @return String
96 107
      */
97 108
     public static Integer getLength(String s) {
98
-        return null;
109
+        return s.length();
99 110
     }
100 111
 
101 112
     /**
@@ -109,7 +120,7 @@ public class StringParser
109 120
      * @return String
110 121
      */
111 122
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
123
+        return s1.equals(s2);
113 124
     }
114 125
 
115 126
     /**
@@ -123,6 +134,6 @@ public class StringParser
123 134
      * @return String
124 135
      */
125 136
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
137
+        return s1.equalsIgnoreCase(s2);
127 138
     }
128 139
 }

+ 4
- 4
package.bluej Visa fil

@@ -3,16 +3,16 @@ dependency1.from=StringParserTest
3 3
 dependency1.to=StringParser
4 4
 dependency1.type=UsesDependency
5 5
 editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=455
8
-editor.fx.0.y=51
6
+editor.fx.0.width=1040
7
+editor.fx.0.x=400
8
+editor.fx.0.y=123
9 9
 objectbench.height=164
10 10
 objectbench.width=776
11 11
 package.divider.horizontal=0.6
12 12
 package.divider.vertical=0.6845018450184502
13 13
 package.editor.height=364
14 14
 package.editor.width=674
15
-package.editor.x=0
15
+package.editor.x=288
16 16
 package.editor.y=23
17 17
 package.frame.height=600
18 18
 package.frame.width=800