Browse Source

JavaStringCheese FINISHED

Nathan Hall 6 years ago
parent
commit
2ac52d38bc
5 changed files with 39 additions and 21 deletions
  1. BIN
      StringParser.class
  2. 34
    10
      StringParser.java
  3. BIN
      StringParserTest.class
  4. 2
    0
      StringParserTest.java
  5. 3
    11
      package.bluej

BIN
StringParser.class View File


+ 34
- 10
StringParser.java View File

@@ -1,3 +1,4 @@
1
+package JavaStringCheese;
1 2
 
2 3
 /**
3 4
  * An introduction to Strings and String methods.
@@ -15,7 +16,7 @@ public class StringParser
15 16
      */
16 17
     public static String upperCaseString(String s)
17 18
     {
18
-        return null;
19
+        return s.toUpperCase();
19 20
     }
20 21
 
21 22
     /**
@@ -26,7 +27,7 @@ public class StringParser
26 27
      * @return String
27 28
      */
28 29
     public static String lowerCaseString(String s) {
29
-        return null;
30
+        return s.toLowerCase();
30 31
     }
31 32
 
32 33
     /**
@@ -37,7 +38,7 @@ public class StringParser
37 38
      * @return String
38 39
      */
39 40
     public static Character getFirstCharacter(String s) {
40
-        return null;
41
+        return s.charAt(0);
41 42
     }
42 43
 
43 44
     /**
@@ -49,7 +50,7 @@ public class StringParser
49 50
      * @return String
50 51
      */
51 52
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
53
+        return s.charAt(n);
53 54
     }
54 55
 
55 56
     /**
@@ -60,7 +61,7 @@ public class StringParser
60 61
      * @return String
61 62
      */
62 63
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
64
+        return s.substring(0, 1).toUpperCase() + s.substring(1);
64 65
     }
65 66
 
66 67
     /**
@@ -72,7 +73,14 @@ public class StringParser
72 73
      * @return String
73 74
      */
74 75
     public static String camelCaseString(String s) {
75
-        return null;
76
+        s = s.toLowerCase();
77
+        String camelCase = new String();
78
+        int word2 = s.indexOf(" ") + 1;
79
+
80
+        camelCase = s.substring(0, 1).toUpperCase() + s.substring(1, word2 - 1 ) + 
81
+        s.substring(word2, word2 + 1).toUpperCase() + s.substring(word2 +1);
82
+
83
+        return camelCase;
76 84
     }
77 85
 
78 86
     /**
@@ -84,7 +92,9 @@ public class StringParser
84 92
      * @return String
85 93
      */
86 94
     public static String snakeCaseString(String s) {
87
-        return null;
95
+        String str = s.toLowerCase().replace(" ","_");
96
+
97
+        return str;
88 98
     }
89 99
 
90 100
     /**
@@ -95,7 +105,7 @@ public class StringParser
95 105
      * @return String
96 106
      */
97 107
     public static Integer getLength(String s) {
98
-        return null;
108
+        return s.length();
99 109
     }
100 110
 
101 111
     /**
@@ -109,7 +119,14 @@ public class StringParser
109 119
      * @return String
110 120
      */
111 121
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
122
+        boolean isIt = false;
123
+
124
+        if (s1 == s2){
125
+            isIt = true;
126
+
127
+        }
128
+
129
+        return isIt;
113 130
     }
114 131
 
115 132
     /**
@@ -123,6 +140,13 @@ public class StringParser
123 140
      * @return String
124 141
      */
125 142
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
143
+        boolean isIt = false;
144
+
145
+        if (s1.equalsIgnoreCase(s2)){
146
+            isIt = true;
147
+
148
+        }
149
+
150
+        return isIt;
127 151
     }
128 152
 }

BIN
StringParserTest.class View File


+ 2
- 0
StringParserTest.java View File

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

+ 3
- 11
package.bluej View File

@@ -1,26 +1,18 @@
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
12 5
 package.divider.vertical=0.6845018450184502
13 6
 package.editor.height=364
14 7
 package.editor.width=674
15
-package.editor.x=0
16
-package.editor.y=23
8
+package.editor.x=196
9
+package.editor.y=156
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