Przeglądaj źródła

completed string chz lab

Connor Dunnigan 8 lat temu
rodzic
commit
0989700d4b
4 zmienionych plików z 29 dodań i 18 usunięć
  1. BIN
      StringParser.class
  2. 2
    2
      StringParser.ctxt
  3. 26
    15
      StringParser.java
  4. 1
    1
      package.bluej

BIN
StringParser.class Wyświetl plik


+ 2
- 2
StringParser.ctxt Wyświetl plik

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=\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
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=\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
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=\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
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=\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
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=\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
34
 numComments=11
34
 numComments=11

+ 26
- 15
StringParser.java Wyświetl plik

1
-
1
+import java.lang.*;
2
 /**
2
 /**
3
  * An introduction to Strings and String methods.
3
  * An introduction to Strings and String methods.
4
  *
4
  *
15
      */
15
      */
16
     public static String upperCaseString(String s)
16
     public static String upperCaseString(String s)
17
     {
17
     {
18
-        return null;
18
+      return s.toUpperCase();
19
     }
19
     }
20
 
20
 
21
     /**
21
     /**
26
      * @return String
26
      * @return String
27
      */
27
      */
28
     public static String lowerCaseString(String s) {
28
     public static String lowerCaseString(String s) {
29
-        return null;
29
+        return s.toLowerCase();
30
     }
30
     }
31
 
31
 
32
     /**
32
     /**
37
      * @return String
37
      * @return String
38
      */
38
      */
39
     public static Character getFirstCharacter(String s) {
39
     public static Character getFirstCharacter(String s) {
40
-        return null;
40
+        return s.charAt(0);
41
     }
41
     }
42
 
42
 
43
     /**
43
     /**
49
      * @return String
49
      * @return String
50
      */
50
      */
51
     public static Character getNthCharacter(String s, Integer n) {
51
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
52
+        return s.charAt(n);
53
     }
53
     }
54
 
54
 
55
     /**
55
     /**
60
      * @return String
60
      * @return String
61
      */
61
      */
62
     public static String upperCaseFirstCharacter(String s) {
62
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
63
+        
64
+        s = s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase();
65
+        return s;
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
+        String camelStr = new String();
78
+        
79
+        String[] arrS = s.split(" ",0);
80
+        for(String str : arrS)
81
+            camelStr += str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase();
82
+        
83
+        return camelStr;
76
     }
84
     }
77
 
85
 
78
     /**
86
     /**
84
      * @return String
92
      * @return String
85
      */
93
      */
86
     public static String snakeCaseString(String s) {
94
     public static String snakeCaseString(String s) {
87
-        return null;
95
+        String snake = new String();
96
+        s = s.toLowerCase();
97
+        snake = s.replaceAll(" ","_");
98
+        return snake;
88
     }
99
     }
89
 
100
 
90
     /**
101
     /**
95
      * @return String
106
      * @return String
96
      */
107
      */
97
     public static Integer getLength(String s) {
108
     public static Integer getLength(String s) {
98
-        return null;
109
+        return s.length();
99
     }
110
     }
100
 
111
 
101
     /**
112
     /**
102
      * Takes in two strings and returns true if they are equal
113
      * Takes in two strings and returns true if they are equal
103
-     * E.G. example and shelf would return false. 
104
-     * cat and CaT would return false. 
114
+     * E.G. example and shelf would return false.
115
+     * cat and CaT would return false.
105
      * Dog and Dog would return true
116
      * Dog and Dog would return true
106
      *
117
      *
107
      * @param s1
118
      * @param s1
109
      * @return String
120
      * @return String
110
      */
121
      */
111
     public static Boolean isEqual(String s1, String s2) {
122
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
123
+        return s1.equals(s2);
113
     }
124
     }
114
 
125
 
115
     /**
126
     /**
116
      * Takes in two strings and returns true if they are equal
127
      * Takes in two strings and returns true if they are equal
117
-     * E.G. example and shelf would return false. 
118
-     * cat and CaT would return true. 
128
+     * E.G. example and shelf would return false.
129
+     * cat and CaT would return true.
119
      * Dog and Dog would return true
130
      * Dog and Dog would return true
120
      *
131
      *
121
      * @param s1
132
      * @param s1
123
      * @return String
134
      * @return String
124
      */
135
      */
125
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
136
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
137
+        return s1.equalsIgnoreCase(s2);
127
     }
138
     }
128
 }
139
 }

+ 1
- 1
package.bluej Wyświetl plik

5
 editor.fx.0.height=722
5
 editor.fx.0.height=722
6
 editor.fx.0.width=800
6
 editor.fx.0.width=800
7
 editor.fx.0.x=455
7
 editor.fx.0.x=455
8
-editor.fx.0.y=51
8
+editor.fx.0.y=25
9
 objectbench.height=164
9
 objectbench.height=164
10
 objectbench.width=776
10
 objectbench.width=776
11
 package.divider.horizontal=0.6
11
 package.divider.horizontal=0.6