#43 JavaStringCheese

Открыто
jtinkler хочет смерджить 1 коммит(ов) из jtinkler/JavaStringCheese:master в master
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
 #BlueJ class context
1
 #BlueJ class context
2
 comment0.target=StringParser
2
 comment0.target=StringParser
3
-comment0.text=\n\ An\ introduction\ to\ Strings\ and\ String\ methods.\n\n\ @author\ Wilhem\ Alcivar\n
4
 comment1.params=s
3
 comment1.params=s
5
 comment1.target=java.lang.String\ upperCaseString(java.lang.String)
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
 comment10.params=s1\ s2
5
 comment10.params=s1\ s2
8
 comment10.target=java.lang.Boolean\ isEqualIgnoreCase(java.lang.String,\ java.lang.String)
6
 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
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
 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
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
 comment3.params=s
11
 comment3.params=s
14
 comment3.target=java.lang.Character\ getFirstCharacter(java.lang.String)
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
 comment4.params=s\ n
14
 comment4.params=s\ n
17
 comment4.target=java.lang.Character\ getNthCharacter(java.lang.String,\ java.lang.Integer)
15
 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
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
  *
4
  *
5
  * @author Wilhem Alcivar
5
  * @author Wilhem Alcivar
6
  */
6
  */
7
+
8
+import java.util.*;
9
+
10
+
7
 public class StringParser
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
      * Takes a String and returns that String with all characters lowercased.
32
      * Takes a String and returns that String with all characters lowercased.
23
      * E.G. MOUSE would become mouse. dOnUt would become donut.
33
      * E.G. MOUSE would become mouse. dOnUt would become donut.
26
      * @return String
36
      * @return String
27
      */
37
      */
28
     public static String lowerCaseString(String s) {
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
      * Takes a String and returns the first character of that string.
47
      * Takes a String and returns the first character of that string.
34
      * E.G. cat would return c. Embark would return E.
48
      * E.G. cat would return c. Embark would return E.
35
      *
49
      *
36
      * @param s
50
      * @param s
37
      * @return String
51
      * @return String
52
+     * 
38
      */
53
      */
54
+    
39
     public static Character getFirstCharacter(String s) {
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
      * Takes a String and returns the character at index n of that string.
63
      * Takes a String and returns the character at index n of that string.
45
      * E.G. cat, 2 would return t. Embark, 4 would return r.
64
      * E.G. cat, 2 would return t. Embark, 4 would return r.
49
      * @return String
68
      * @return String
50
      */
69
      */
51
     public static Character getNthCharacter(String s, Integer n) {
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
      * @return String
81
      * @return String
61
      */
82
      */
62
     public static String upperCaseFirstCharacter(String s) {
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
      * @return String
101
      * @return String
73
      */
102
      */
74
     public static String camelCaseString(String s) {
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
      * @return String
128
      * @return String
85
      */
129
      */
86
     public static String snakeCaseString(String s) {
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
      * Takes a String and returns the length of that string
140
      * Takes a String and returns the length of that string
95
      * @return String
144
      * @return String
96
      */
145
      */
97
     public static Integer getLength(String s) {
146
     public static Integer getLength(String s) {
98
-        return null;
147
+        return s.length(); 
99
     }
148
     }
100
 
149
 
101
     /**
150
     /**
109
      * @return String
158
      * @return String
110
      */
159
      */
111
     public static Boolean isEqual(String s1, String s2) {
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
      * @return String
175
      * @return String
124
      */
176
      */
125
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
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
 #BlueJ package file
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
 package.divider.horizontal=0.6
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
 package.numTargets=2
17
 package.numTargets=2
21
 package.showExtends=true
18
 package.showExtends=true
22
 package.showUses=true
19
 package.showUses=true
38
 target2.showInterface=false
35
 target2.showInterface=false
39
 target2.type=UnitTestTargetJunit4
36
 target2.type=UnitTestTargetJunit4
40
 target2.width=130
37
 target2.width=130
41
-target2.x=140
42
-target2.y=40
38
+target2.x=210
39
+target2.y=80