Nira Parikh 8 lat temu
rodzic
commit
2cbe9df9ae
4 zmienionych plików z 67 dodań i 24 usunięć
  1. BIN
      StringParser.class
  2. 1
    1
      StringParser.ctxt
  3. 59
    16
      StringParser.java
  4. 7
    7
      package.bluej

BIN
StringParser.class Wyświetl plik


+ 1
- 1
StringParser.ctxt Wyświetl plik

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=\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
19
 comment5.params=s
19
 comment5.params=s
20
 comment5.target=java.lang.String\ upperCaseFirstCharacter(java.lang.String)
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=\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\n
22
 comment6.params=s
22
 comment6.params=s
23
 comment6.target=java.lang.String\ camelCaseString(java.lang.String)
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=\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

+ 59
- 16
StringParser.java Wyświetl plik

15
      */
15
      */
16
     public static String upperCaseString(String s)
16
     public static String upperCaseString(String s)
17
     {
17
     {
18
-        return null;
18
+        String abc = s.toUpperCase();
19
+        return abc;
19
     }
20
     }
20
 
21
 
21
     /**
22
     /**
26
      * @return String
27
      * @return String
27
      */
28
      */
28
     public static String lowerCaseString(String s) {
29
     public static String lowerCaseString(String s) {
29
-        return null;
30
+        String abc = s.toLowerCase();
31
+        return abc;
30
     }
32
     }
31
 
33
 
32
     /**
34
     /**
37
      * @return String
39
      * @return String
38
      */
40
      */
39
     public static Character getFirstCharacter(String s) {
41
     public static Character getFirstCharacter(String s) {
40
-        return null;
42
+        char first= s.charAt(0);
43
+        return first;
41
     }
44
     }
42
 
45
 
43
-    /**
46
+    /*
44
      * Takes a String and returns the character at index n of that string.
47
      * 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.
48
      * E.G. cat, 2 would return t. Embark, 4 would return r.
46
      *
49
      *
48
      * @param n
51
      * @param n
49
      * @return String
52
      * @return String
50
      */
53
      */
51
-    public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
53
-    }
54
 
54
 
55
-    /**
55
+    public static Character getNthCharacter(String s, Integer n) {   
56
+        char fir = s.charAt(n);
57
+
58
+        return fir;
59
+    }    
60
+
61
+    /*
56
      * Takes a String and returns that string with the first character uppercased.
62
      * Takes a String and returns that string with the first character uppercased.
57
      * E.G. cat would return Cat. cofFee would return CofFee.
63
      * E.G. cat would return Cat. cofFee would return CofFee.
58
      *
64
      *
59
      * @param s
65
      * @param s
60
      * @return String
66
      * @return String
67
+     *
61
      */
68
      */
62
     public static String upperCaseFirstCharacter(String s) {
69
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
70
+        String capital = s.substring(0, 1).toUpperCase() + s.substring(1);
71
+        return capital;
72
+
64
     }
73
     }
65
 
74
 
66
-    /**
75
+    /*
67
      * Takes a String and returns that string with the first character of each word in it uppercased
76
      * Takes a String and returns that string with the first character of each word in it uppercased
68
      * and then joined.
77
      * and then joined.
69
      * E.G. dog whistle would return DogWhistle. adjuNCT pRoFessOR would return AdjuctProfessor.
78
      * E.G. dog whistle would return DogWhistle. adjuNCT pRoFessOR would return AdjuctProfessor.
72
      * @return String
81
      * @return String
73
      */
82
      */
74
     public static String camelCaseString(String s) {
83
     public static String camelCaseString(String s) {
75
-        return null;
84
+        String sum=s.toLowerCase();
85
+        
86
+        String first=sum.split(" ")[0];
87
+        String sec=sum.split(" ")[1];
88
+        
89
+        String firstLet = first.substring(0,1).toUpperCase()+first.substring(1).toLowerCase();
90
+        String othLetters = sec.substring(0,1).toUpperCase()+sec.substring(1).toLowerCase();
91
+        String total=firstLet+othLetters;
92
+        return total ;
76
     }
93
     }
77
 
94
 
78
-    /**
95
+       
96
+        
97
+    
98
+    /*
79
      * Takes a String and returns that string with each character lowercased
99
      * Takes a String and returns that string with each character lowercased
80
      * and then joined with an underscore
100
      * and then joined with an underscore
81
      * E.G. dog whistle would return dog_whistle. adjuNCT pRoFessOR would return adjuct_professor.
101
      * E.G. dog whistle would return dog_whistle. adjuNCT pRoFessOR would return adjuct_professor.
84
      * @return String
104
      * @return String
85
      */
105
      */
86
     public static String snakeCaseString(String s) {
106
     public static String snakeCaseString(String s) {
87
-        return null;
107
+
108
+        int snakeCase = s.length();
109
+        String Sti = "";
110
+
111
+        for (int n = 0; n < snakeCase; n++){
112
+            if (s.charAt (n) == ' '){
113
+                Sti = Sti + '_';
114
+            }
115
+            else 
116
+                Sti = Sti + Character.toLowerCase (s.charAt(n));
117
+        }
118
+
119
+        return Sti;
88
     }
120
     }
89
 
121
 
90
     /**
122
     /**
94
      * @param s
126
      * @param s
95
      * @return String
127
      * @return String
96
      */
128
      */
129
+
97
     public static Integer getLength(String s) {
130
     public static Integer getLength(String s) {
98
-        return null;
131
+        return s.length();
132
+
99
     }
133
     }
100
 
134
 
101
     /**
135
     /**
109
      * @return String
143
      * @return String
110
      */
144
      */
111
     public static Boolean isEqual(String s1, String s2) {
145
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
146
+        if(s1.equals(s2)) {
147
+            return true;
148
+        } else {
149
+            return false;
150
+        }
113
     }
151
     }
114
 
152
 
115
     /**
153
     /**
123
      * @return String
161
      * @return String
124
      */
162
      */
125
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
163
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
164
+        if (s1.equalsIgnoreCase(s2)){
165
+            return true;
166
+        } else {
167
+            return false;
168
+        }
169
+
127
     }
170
     }
128
 }
171
 }

+ 7
- 7
package.bluej Wyświetl plik

2
 dependency1.from=StringParserTest
2
 dependency1.from=StringParserTest
3
 dependency1.to=StringParser
3
 dependency1.to=StringParser
4
 dependency1.type=UsesDependency
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=869
7
+editor.fx.0.x=400
8
+editor.fx.0.y=23
9
 objectbench.height=164
9
 objectbench.height=164
10
-objectbench.width=776
10
+objectbench.width=461
11
 package.divider.horizontal=0.6
11
 package.divider.horizontal=0.6
12
 package.divider.vertical=0.6845018450184502
12
 package.divider.vertical=0.6845018450184502
13
 package.editor.height=364
13
 package.editor.height=364
14
 package.editor.width=674
14
 package.editor.width=674
15
-package.editor.x=0
16
-package.editor.y=23
15
+package.editor.x=241
16
+package.editor.y=142
17
 package.frame.height=600
17
 package.frame.height=600
18
 package.frame.width=800
18
 package.frame.width=800
19
 package.numDependencies=1
19
 package.numDependencies=1