Quellcode durchsuchen

JavaStringCheese

Soujanya Buragapu vor 6 Jahren
Ursprung
Commit
9068d996a7
3 geänderte Dateien mit 62 neuen und 26 gelöschten Zeilen
  1. BIN
      StringParser.class
  2. 56
    20
      StringParser.java
  3. 6
    6
      package.bluej

BIN
StringParser.class Datei anzeigen


+ 56
- 20
StringParser.java Datei anzeigen

@@ -15,7 +15,8 @@ public class StringParser
15 15
      */
16 16
     public static String upperCaseString(String s)
17 17
     {
18
-        return null;
18
+        String str;
19
+        return str= s.toUpperCase();
19 20
     }
20 21
 
21 22
     /**
@@ -25,8 +26,10 @@ public class StringParser
25 26
      * @param s
26 27
      * @return String
27 28
      */
28
-    public static String lowerCaseString(String s) {
29
-        return null;
29
+    public static String lowerCaseString(String s) 
30
+    {
31
+        String str;
32
+        return str = s.toLowerCase();
30 33
     }
31 34
 
32 35
     /**
@@ -36,8 +39,10 @@ public class StringParser
36 39
      * @param s
37 40
      * @return String
38 41
      */
39
-    public static Character getFirstCharacter(String s) {
40
-        return null;
42
+    public static Character getFirstCharacter(String s) 
43
+    {
44
+
45
+        return s.charAt(0);
41 46
     }
42 47
 
43 48
     /**
@@ -48,8 +53,10 @@ public class StringParser
48 53
      * @param n
49 54
      * @return String
50 55
      */
51
-    public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
56
+    public static Character getNthCharacter(String s, Integer n)
57
+    {
58
+
59
+        return s.charAt(n);
53 60
     }
54 61
 
55 62
     /**
@@ -59,8 +66,10 @@ public class StringParser
59 66
      * @param s
60 67
      * @return String
61 68
      */
62
-    public static String upperCaseFirstCharacter(String s) {
63
-        return null;
69
+    public static String upperCaseFirstCharacter(String s) 
70
+    {
71
+        String str = s.substring(0,1).toUpperCase()+s.substring(1);
72
+        return str;
64 73
     }
65 74
 
66 75
     /**
@@ -71,10 +80,14 @@ public class StringParser
71 80
      * @param s
72 81
      * @return String
73 82
      */
74
-    public static String camelCaseString(String s) {
75
-        return null;
83
+    public static String camelCaseString(String s)
84
+    {
85
+        String [] list = s.split(" ");
86
+        String str1 = list[0];
87
+        String str2 = list[1];
88
+        return (""+str1.toUpperCase().charAt(0)+str1.toLowerCase().substring(1,str1.length())+str2.toUpperCase().charAt(0)+str2.toLowerCase().substring(1,str2.length()));
76 89
     }
77
-
90
+    
78 91
     /**
79 92
      * Takes a String and returns that string with each character lowercased
80 93
      * and then joined with an underscore
@@ -83,8 +96,19 @@ public class StringParser
83 96
      * @param s
84 97
      * @return String
85 98
      */
86
-    public static String snakeCaseString(String s) {
87
-        return null;
99
+    public static String snakeCaseString(String s) 
100
+    {
101
+        int n = s.length();
102
+        String str = "";
103
+        for(int i = 0; i < n; i++)
104
+        {
105
+            if(s.charAt(i) == ' ')
106
+            str = str + '_';
107
+            else
108
+            str = str + Character.toLowerCase(s.charAt(i));
109
+        }
110
+        return str;
111
+        
88 112
     }
89 113
 
90 114
     /**
@@ -94,8 +118,9 @@ public class StringParser
94 118
      * @param s
95 119
      * @return String
96 120
      */
97
-    public static Integer getLength(String s) {
98
-        return null;
121
+    public static Integer getLength(String s) 
122
+    {
123
+        return s.length();
99 124
     }
100 125
 
101 126
     /**
@@ -108,8 +133,17 @@ public class StringParser
108 133
      * @param s2
109 134
      * @return String
110 135
      */
111
-    public static Boolean isEqual(String s1, String s2) {
112
-        return null;
136
+    public static Boolean isEqual(String s1, String s2) 
137
+    {
138
+        if(s1.equals(s2))
139
+        {
140
+            return true;
141
+        }
142
+        else
143
+        {
144
+            return false;
145
+        }
146
+
113 147
     }
114 148
 
115 149
     /**
@@ -122,7 +156,9 @@ public class StringParser
122 156
      * @param s2
123 157
      * @return String
124 158
      */
125
-    public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
159
+    public static Boolean isEqualIgnoreCase(String s1, String s2) 
160
+    {
161
+      return (s1.equalsIgnoreCase(s2));
162
+        
127 163
     }
128 164
 }

+ 6
- 6
package.bluej Datei anzeigen

@@ -2,17 +2,17 @@
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
5
+editor.fx.0.height=709
6
+editor.fx.0.width=813
7
+editor.fx.0.x=214
8
+editor.fx.0.y=23
9 9
 objectbench.height=164
10
-objectbench.width=776
10
+objectbench.width=461
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=431
16 16
 package.editor.y=23
17 17
 package.frame.height=600
18 18
 package.frame.width=800