Browse Source

here. enjoy

Amy Gill 6 years ago
parent
commit
8dfc662719

+ 37
- 7
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
18
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
19
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return firstSegment.concat(secondSegment);
20
+        return firstSegment + secondSegment;
21
     }
21
     }
22
 
22
 
23
     /**
23
     /**
42
      * @return the last 3 characters of `input`
42
      * @return the last 3 characters of `input`
43
      */
43
      */
44
     public static String getSuffix(String input){
44
     public static String getSuffix(String input){
45
-        return input.substring(0,-3);
45
+        return input.substring(input.length()-3, input.length());
46
 
46
 
47
     }
47
     }
48
 
48
 
52
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
53
      */
53
      */
54
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
55
-        return true;
55
+        return inputValue.equalsIgnoreCase(comparableValue);
56
     }
56
     }
57
 
57
 
58
     /**
58
     /**
60
      * @return the middle character of `inputValue`
60
      * @return the middle character of `inputValue`
61
      */
61
      */
62
     public static Character getMiddleCharacter(String inputValue){
62
     public static Character getMiddleCharacter(String inputValue){
63
-        return getMiddleCharacter(inputValue);
63
+        int length;
64
+        int position;
65
+        if (inputValue.length() % 2 ==0) {
66
+            position = inputValue.length()/2-1;
67
+            length = 2;
68
+
69
+        } else {
70
+            position = inputValue.length()/2;
71
+            length = 1;
72
+        }
73
+
74
+        return inputValue.charAt(position);
64
     }
75
     }
65
 
76
 
66
     /**
77
     /**
68
      * @return the first sequence of characters
79
      * @return the first sequence of characters
69
      */
80
      */
70
     public static String getFirstWord(String spaceDelimitedString){
81
     public static String getFirstWord(String spaceDelimitedString){
71
-        return getFirstWord(spaceDelimitedString);
82
+
83
+        String answer = "";
84
+
85
+        for (int i = 0; i< spaceDelimitedString.length(); i++){
86
+            if (spaceDelimitedString.charAt(i) == ' ') {
87
+                answer = spaceDelimitedString.substring(0, i);
88
+            }
89
+        }
90
+        return answer;
72
     }
91
     }
73
 
92
 
74
     /**
93
     /**
76
      * @return the second word of a string delimited by spaces.
95
      * @return the second word of a string delimited by spaces.
77
      */
96
      */
78
     public static String getSecondWord(String spaceDelimitedString){
97
     public static String getSecondWord(String spaceDelimitedString){
79
-        return getSecondWord(spaceDelimitedString);
98
+
99
+        String[] answer = spaceDelimitedString.split(" ");
100
+
101
+        return answer[1];
80
     }
102
     }
81
 
103
 
104
+
105
+
82
     /**
106
     /**
83
      * @param stringToReverse
107
      * @param stringToReverse
84
      * @return an identical string with characters in reverse order.
108
      * @return an identical string with characters in reverse order.
85
      */
109
      */
86
     public static String reverseTheTwo(String stringToReverse){
110
     public static String reverseTheTwo(String stringToReverse){
87
-        return reverseTheTwo(stringToReverse);
111
+        String answer = "";
112
+
113
+        for (int i = stringToReverse.length()-1; i >= 0; i--) {
114
+            answer = answer + stringToReverse.charAt(i);
115
+        }
116
+
117
+        return answer;
88
     }
118
     }
89
 }
119
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java View File

56
     public void substringBeginTest(){
56
     public void substringBeginTest(){
57
         // : Given
57
         // : Given
58
         String input = "Hello";
58
         String input = "Hello";
59
-        String expected = "olleH";
59
+        String expected = "Hel";
60
 
60
 
61
         // : When
61
         // : When
62
         String actual = StringUtilities.getPrefix(input);
62
         String actual = StringUtilities.getPrefix(input);
154
         String expected = "Wilmington";
154
         String expected = "Wilmington";
155
 
155
 
156
         // : When
156
         // : When
157
-        String actual = StringUtilities.getFirstWord(input);
157
+        String actual = StringUtilities.getSecondWord(input);
158
 
158
 
159
         // : Then
159
         // : Then
160
         assertEquals(expected, actual);
160
         assertEquals(expected, actual);

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class View File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class View File