Karousha Fennimore 6 anos atrás
pai
commit
3865a23816

+ 2
- 2
ChapterOneMicro.iml Ver arquivo

@@ -10,7 +10,7 @@
10 10
     </content>
11 11
     <orderEntry type="inheritedJdk" />
12 12
     <orderEntry type="sourceFolder" forTests="false" />
13
-    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
14
-    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15 15
   </component>
16 16
 </module>

+ 57
- 22
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Ver arquivo

@@ -8,81 +8,116 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public static String getHelloWorld() {
11
-        return null;
11
+
12
+        return "Hello World";
12 13
     }
13 14
 
14 15
     /**
15
-     * @param firstSegment a string to be added to
16
+     * @param firstSegment  a string to be added to
16 17
      * @param secondSegment a string to add
17 18
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 19
      */
19
-    public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+    public static String concatenation(String firstSegment, String secondSegment) {
21
+
22
+        return firstSegment + secondSegment;
21 23
     }
22 24
 
23 25
     /**
24
-     * @param firstSegment a string to be added to
26
+     * @param firstSegment  a string to be added to
25 27
      * @param secondSegment a string to add
26 28
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 29
      */
28
-    public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
30
+    public static String concatenation(int firstSegment, String secondSegment) {
31
+
32
+        return firstSegment + secondSegment;
30 33
     }
31 34
 
32 35
     /**
33 36
      * @param input a string to be manipulated
34 37
      * @return the first 3 characters of `input`
35 38
      */
36
-    public static String getPrefix(String input){
37
-        return null;
39
+    public static String getPrefix(String input) {
40
+
41
+        return input.substring(0, 3);
38 42
     }
39 43
 
40 44
     /**
41 45
      * @param input a string to be manipulated
42 46
      * @return the last 3 characters of `input`
43 47
      */
44
-    public static String getSuffix(String input){
45
-        return null;
48
+    public static String getSuffix(String input) {
49
+
50
+        return input.substring(input.length() - 3, input.length());
46 51
     }
47 52
 
48 53
     /**
49
-     * @param inputValue the value to be compared
54
+     * @param inputValue      the value to be compared
50 55
      * @param comparableValue the value to be compared against
51 56
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 57
      */
53
-    public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
58
+    public static Boolean compareTwoStrings(String inputValue, String comparableValue) {
59
+
60
+        return inputValue.equalsIgnoreCase(comparableValue);
55 61
     }
56 62
 
57 63
     /**
58 64
      * @param inputValue the value input from user
59 65
      * @return the middle character of `inputValue`
60 66
      */
61
-    public static Character getMiddleCharacter(String inputValue){
62
-        return null;
67
+    public static Character getMiddleCharacter(String inputValue) {
68
+        int length;
69
+        int position;
70
+        if (inputValue.length() % 2 == 0) {
71
+            position = inputValue.length() / 2 - 1;
72
+            length = 2;
73
+        } else {
74
+            position = inputValue.length() / 2;
75
+            length = 1;
76
+        }
77
+        return inputValue.charAt(position);
63 78
     }
64 79
 
65 80
     /**
66 81
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 82
      * @return the first sequence of characters
68 83
      */
69
-    public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
84
+    public static String getFirstWord(String spaceDelimitedString) {
85
+
86
+        String answer = "";
87
+
88
+        for (int i = 0; i < spaceDelimitedString.length(); i++) {
89
+            if (spaceDelimitedString.charAt(i) == ' ') {
90
+                answer = spaceDelimitedString.substring(0, i);
91
+            }
92
+        }
93
+
94
+        return answer;
71 95
     }
72 96
 
97
+
73 98
     /**
74 99
      * @param spaceDelimitedString a string delimited by spaces
75 100
      * @return the second word of a string delimited by spaces.
76 101
      */
77
-    public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
102
+    public static String getSecondWord(String spaceDelimitedString) {
103
+        String[] answer = spaceDelimitedString.split(" ");
104
+
105
+
106
+        return answer[1];
79 107
     }
80 108
 
109
+
81 110
     /**
82 111
      * @param stringToReverse
83 112
      * @return an identical string with characters in reverse order.
84 113
      */
85
-    public static String reverse(String stringToReverse){
86
-        return null;
114
+    public static String reverse(String stringToReverse) {
115
+
116
+        String reverse = "";
117
+
118
+        for (int i = stringToReverse.length() - 1; i >= 0; i--) {
119
+            reverse = reverse + stringToReverse.charAt(i);
120
+        }
121
+        return reverse;
87 122
     }
88 123
 }