jtith5 8 лет назад
Родитель
Сommit
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
 #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
3
+comment0.text=\r\n\ An\ introduction\ to\ Strings\ and\ String\ methods.\r\n\r\n\ @author\ Wilhem\ Alcivar\r\n
4
 comment1.params=s
4
 comment1.params=s
5
 comment1.target=java.lang.String\ upperCaseString(java.lang.String)
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
 comment10.params=s1\ s2
7
 comment10.params=s1\ s2
8
 comment10.target=java.lang.Boolean\ isEqualIgnoreCase(java.lang.String,\ java.lang.String)
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
 comment2.params=s
10
 comment2.params=s
11
 comment2.target=java.lang.String\ lowerCaseString(java.lang.String)
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
 comment3.params=s
13
 comment3.params=s
14
 comment3.target=java.lang.Character\ getFirstCharacter(java.lang.String)
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
 comment4.params=s\ n
16
 comment4.params=s\ n
17
 comment4.target=java.lang.Character\ getNthCharacter(java.lang.String,\ java.lang.Integer)
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
 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=\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
 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=\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
 comment7.params=s
25
 comment7.params=s
26
 comment7.target=java.lang.String\ snakeCaseString(java.lang.String)
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
 comment8.params=s
28
 comment8.params=s
29
 comment8.target=java.lang.Integer\ getLength(java.lang.String)
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
 comment9.params=s1\ s2
31
 comment9.params=s1\ s2
32
 comment9.target=java.lang.Boolean\ isEqual(java.lang.String,\ java.lang.String)
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
 numComments=11
34
 numComments=11

+ 40
- 10
StringParser.java Просмотреть файл

1
+import java.util.*; 
1
 
2
 
2
 /**
3
 /**
3
  * An introduction to Strings and String methods.
4
  * An introduction to Strings and String methods.
15
      */
16
      */
16
     public static String upperCaseString(String s)
17
     public static String upperCaseString(String s)
17
     {
18
     {
18
-        return null;
19
+        return s.toUpperCase();
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
+        return s.toLowerCase();
30
     }
31
     }
31
 
32
 
32
     /**
33
     /**
37
      * @return String
38
      * @return String
38
      */
39
      */
39
     public static Character getFirstCharacter(String s) {
40
     public static Character getFirstCharacter(String s) {
40
-        return null;
41
+        return s.charAt(0);
41
     }
42
     }
42
 
43
 
43
     /**
44
     /**
49
      * @return String
50
      * @return String
50
      */
51
      */
51
     public static Character getNthCharacter(String s, Integer n) {
52
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
53
+        return s.charAt(n);
53
     }
54
     }
54
 
55
 
55
     /**
56
     /**
60
      * @return String
61
      * @return String
61
      */
62
      */
62
     public static String upperCaseFirstCharacter(String s) {
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
      * @return String
74
      * @return String
73
      */
75
      */
74
     public static String camelCaseString(String s) {
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
      * @return String
107
      * @return String
85
      */
108
      */
86
     public static String snakeCaseString(String s) {
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
      * @return String
119
      * @return String
96
      */
120
      */
97
     public static Integer getLength(String s) {
121
     public static Integer getLength(String s) {
98
-        return null;
122
+        return s.length();
99
     }
123
     }
100
 
124
 
101
     /**
125
     /**
109
      * @return String
133
      * @return String
110
      */
134
      */
111
     public static Boolean isEqual(String s1, String s2) {
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
      * @return String
149
      * @return String
124
      */
150
      */
125
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
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
 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
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
 package.divider.horizontal=0.6
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
 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