瀏覽代碼

completed StringCheese

jtith5 6 年之前
父節點
當前提交
e7b1f86c80
共有 4 個檔案被更改,包括 62 行新增32 行删除
  1. 二進制
      StringParser.class
  2. 11
    11
      StringParser.ctxt
  3. 40
    10
      StringParser.java
  4. 11
    11
      package.bluej

二進制
StringParser.class 查看文件


+ 11
- 11
StringParser.ctxt 查看文件

@@ -1,34 +1,34 @@
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
3
+comment0.text=\r\n\ An\ introduction\ to\ Strings\ and\ String\ methods.\r\n\r\n\ @author\ Wilhem\ Alcivar\r\n
4 4
 comment1.params=s
5 5
 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
6
+comment1.text=\r\n\ Takes\ a\ String\ and\ returns\ that\ String\ with\ all\ characters\ uppercased.\r\n\ E.G.\ cat\ would\ become\ CAT.\ dOnUt\ would\ become\ DONUT.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
7 7
 comment10.params=s1\ s2
8 8
 comment10.target=java.lang.Boolean\ isEqualIgnoreCase(java.lang.String,\ java.lang.String)
9
-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
9
+comment10.text=\r\n\ Takes\ in\ two\ strings\ and\ returns\ true\ if\ they\ are\ equal\r\n\ E.G.\ example\ and\ shelf\ would\ return\ false.\ \r\n\ cat\ and\ CaT\ would\ return\ true.\ \r\n\ Dog\ and\ Dog\ would\ return\ true\r\n\r\n\ @param\ s1\r\n\ @param\ s2\r\n\ @return\ String\r\n
10 10
 comment2.params=s
11 11
 comment2.target=java.lang.String\ lowerCaseString(java.lang.String)
12
-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
12
+comment2.text=\r\n\ Takes\ a\ String\ and\ returns\ that\ String\ with\ all\ characters\ lowercased.\r\n\ E.G.\ MOUSE\ would\ become\ mouse.\ dOnUt\ would\ become\ donut.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
13 13
 comment3.params=s
14 14
 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
15
+comment3.text=\r\n\ Takes\ a\ String\ and\ returns\ the\ first\ character\ of\ that\ string.\r\n\ E.G.\ cat\ would\ return\ c.\ Embark\ would\ return\ E.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
16 16
 comment4.params=s\ n
17 17
 comment4.target=java.lang.Character\ getNthCharacter(java.lang.String,\ java.lang.Integer)
18
-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
18
+comment4.text=\r\n\ Takes\ a\ String\ and\ returns\ the\ character\ at\ index\ n\ of\ that\ string.\r\n\ E.G.\ cat,\ 2\ would\ return\ t.\ Embark,\ 4\ would\ return\ r.\r\n\r\n\ @param\ s\r\n\ @param\ n\r\n\ @return\ String\r\n
19 19
 comment5.params=s
20 20
 comment5.target=java.lang.String\ upperCaseFirstCharacter(java.lang.String)
21
-comment5.text=\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ the\ first\ character\ uppercased.\n\ E.G.\ cat\ would\ return\ Cat.\ cofFee\ would\ return\ CofFee.\n\n\ @param\ s\n\ @return\ String\n
21
+comment5.text=\r\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ the\ first\ character\ uppercased.\r\n\ E.G.\ cat\ would\ return\ Cat.\ cofFee\ would\ return\ CofFee.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
22 22
 comment6.params=s
23 23
 comment6.target=java.lang.String\ camelCaseString(java.lang.String)
24
-comment6.text=\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ the\ first\ character\ of\ each\ word\ in\ it\ uppercased\n\ and\ then\ joined.\n\ E.G.\ dog\ whistle\ would\ return\ DogWhistle.\ adjuNCT\ pRoFessOR\ would\ return\ AdjuctProfessor.\n\n\ @param\ s\n\ @return\ String\n
24
+comment6.text=\r\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ the\ first\ character\ of\ each\ word\ in\ it\ uppercased\r\n\ and\ then\ joined.\r\n\ E.G.\ dog\ whistle\ would\ return\ DogWhistle.\ adjuNCT\ pRoFessOR\ would\ return\ AdjuctProfessor.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
25 25
 comment7.params=s
26 26
 comment7.target=java.lang.String\ snakeCaseString(java.lang.String)
27
-comment7.text=\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ each\ character\ lowercased\n\ and\ then\ joined\ with\ an\ underscore\n\ E.G.\ dog\ whistle\ would\ return\ dog_whistle.\ adjuNCT\ pRoFessOR\ would\ return\ adjuct_professor.\n\n\ @param\ s\n\ @return\ String\n
27
+comment7.text=\r\n\ Takes\ a\ String\ and\ returns\ that\ string\ with\ each\ character\ lowercased\r\n\ and\ then\ joined\ with\ an\ underscore\r\n\ E.G.\ dog\ whistle\ would\ return\ dog_whistle.\ adjuNCT\ pRoFessOR\ would\ return\ adjuct_professor.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
28 28
 comment8.params=s
29 29
 comment8.target=java.lang.Integer\ getLength(java.lang.String)
30
-comment8.text=\n\ Takes\ a\ String\ and\ returns\ the\ length\ of\ that\ string\n\ E.G.\ cat\ would\ return\ 3.\ extra\ would\ return\ 5.\n\n\ @param\ s\n\ @return\ String\n
30
+comment8.text=\r\n\ Takes\ a\ String\ and\ returns\ the\ length\ of\ that\ string\r\n\ E.G.\ cat\ would\ return\ 3.\ extra\ would\ return\ 5.\r\n\r\n\ @param\ s\r\n\ @return\ String\r\n
31 31
 comment9.params=s1\ s2
32 32
 comment9.target=java.lang.Boolean\ isEqual(java.lang.String,\ java.lang.String)
33
-comment9.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\ false.\ \n\ Dog\ and\ Dog\ would\ return\ true\n\n\ @param\ s1\n\ @param\ s2\n\ @return\ String\n
33
+comment9.text=\r\n\ Takes\ in\ two\ strings\ and\ returns\ true\ if\ they\ are\ equal\r\n\ E.G.\ example\ and\ shelf\ would\ return\ false.\ \r\n\ cat\ and\ CaT\ would\ return\ false.\ \r\n\ Dog\ and\ Dog\ would\ return\ true\r\n\r\n\ @param\ s1\r\n\ @param\ s2\r\n\ @return\ String\r\n
34 34
 numComments=11

+ 40
- 10
StringParser.java 查看文件

@@ -1,3 +1,4 @@
1
+import java.util.*; 
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,8 @@ public class StringParser
60 61
      * @return String
61 62
      */
62 63
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
64
+        String cap = s.substring(0,1).toUpperCase() + s.substring(1);
65
+        return cap ;
64 66
     }
65 67
 
66 68
     /**
@@ -72,7 +74,28 @@ public class StringParser
72 74
      * @return String
73 75
      */
74 76
     public static String camelCaseString(String s) {
75
-        return null;
77
+ char[] chars = s.toLowerCase().toCharArray();
78
+        boolean found = false;
79
+        for (int i = 0; i < chars.length; i++) {
80
+            if (!found && Character.isLetter(chars[i])) {
81
+                chars[i] = Character.toUpperCase(chars[i]);
82
+                found = true;
83
+            } else if (Character.isWhitespace(chars[i]) || chars[i]=='.' || chars[i]=='\'') {
84
+                found = false;
85
+
86
+            }
87
+        }
88
+        String test = "";
89
+        for (int i = 0; i < chars.length; i++) {
90
+            test += chars[i];
91
+        }
92
+
93
+        test = test.replaceAll(" ", "");
94
+
95
+
96
+
97
+
98
+        return test;
76 99
     }
77 100
 
78 101
     /**
@@ -84,7 +107,8 @@ public class StringParser
84 107
      * @return String
85 108
      */
86 109
     public static String snakeCaseString(String s) {
87
-        return null;
110
+        String str = s.toLowerCase().replaceAll(" ","_"); 
111
+        return str;
88 112
     }
89 113
 
90 114
     /**
@@ -95,7 +119,7 @@ public class StringParser
95 119
      * @return String
96 120
      */
97 121
     public static Integer getLength(String s) {
98
-        return null;
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
+        if (s1.equals(s2)) {
137
+        return true;
138
+        }else return false;
113 139
     }
114 140
 
115 141
     /**
@@ -123,6 +149,10 @@ public class StringParser
123 149
      * @return String
124 150
      */
125 151
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
152
+        String str1 = s1.toLowerCase();
153
+        String str2 = s2.toLowerCase();
154
+        if (str1.equals(str2)) {
155
+         return true;
156
+        } else return false;
127 157
     }
128 158
 }

+ 11
- 11
package.bluej 查看文件

@@ -2,18 +2,18 @@
2 2
 dependency1.from=StringParserTest
3 3
 dependency1.to=StringParser
4 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
5
+editor.fx.0.height=832
6
+editor.fx.0.width=1255
7
+editor.fx.0.x=2252
8
+editor.fx.0.y=127
9
+objectbench.height=150
10
+objectbench.width=760
11 11
 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
12
+package.divider.vertical=0.686
13
+package.editor.height=336
14
+package.editor.width=670
15
+package.editor.x=2378
16
+package.editor.y=146
17 17
 package.frame.height=600
18 18
 package.frame.width=800
19 19
 package.numDependencies=1