Daniel Horowitz 6 years ago
parent
commit
2ecf76e546

+ 27
- 6
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

29
      */
29
      */
30
     public static String concatenation(int firstSegment, String secondSegment){
30
     public static String concatenation(int firstSegment, String secondSegment){
31
 
31
 
32
-        return firstSegment + "  " + secondSegment;
32
+        return firstSegment + secondSegment;
33
     }
33
     }
34
 
34
 
35
     /**
35
     /**
38
      */
38
      */
39
     public static String getPrefix(String input){
39
     public static String getPrefix(String input){
40
 
40
 
41
-        return input.substring(0,2);
41
+        return input.substring(0,3);
42
     }
42
     }
43
 
43
 
44
     /**
44
     /**
56
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
56
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
57
      */
57
      */
58
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
58
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
59
+
59
         return inputValue.equals(comparableValue);
60
         return inputValue.equals(comparableValue);
60
     }
61
     }
61
 
62
 
65
      */
66
      */
66
     public static Character getMiddleCharacter(String inputValue){
67
     public static Character getMiddleCharacter(String inputValue){
67
 
68
 
68
-        return 'A';
69
+        double mid = inputValue.length() / 2;
70
+        int full = (int)mid;
71
+
72
+            if (inputValue.length() % 2 != 0){
73
+                return inputValue.charAt(full);
74
+
75
+                } else {
76
+
77
+                return inputValue.charAt(full - 1);
78
+                  }
69
     }
79
     }
70
 
80
 
71
     /**
81
     /**
73
      * @return the first sequence of characters
83
      * @return the first sequence of characters
74
      */
84
      */
75
     public static String getFirstWord(String spaceDelimitedString){
85
     public static String getFirstWord(String spaceDelimitedString){
86
+            String list[] = spaceDelimitedString.split(" ", 2);
87
+
88
+                return list[0];
76
 
89
 
77
-        return spaceDelimitedString.split(" ")[0];
78
     }
90
     }
79
 
91
 
80
     /**
92
     /**
83
      */
95
      */
84
     public static String getSecondWord(String spaceDelimitedString){
96
     public static String getSecondWord(String spaceDelimitedString){
85
 
97
 
86
-        return spaceDelimitedString.split(" ")[1];
98
+        String list[] = spaceDelimitedString.split(" ", 2);
99
+
100
+        return list[1];
87
     }
101
     }
88
 
102
 
89
     /**
103
     /**
91
      * @return an identical string with characters in reverse order.
105
      * @return an identical string with characters in reverse order.
92
      */
106
      */
93
     public static String reverseTheTwo(String stringToReverse){
107
     public static String reverseTheTwo(String stringToReverse){
94
-        return null;
108
+
109
+        String flip = "";
110
+
111
+        for(int i = stringToReverse.length()-1; i >= 0; i--){
112
+            flip += stringToReverse.charAt(i);
113
+            }
114
+
115
+            return flip;
95
     }
116
     }
96
 }
117
 }

+ 1
- 1
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);

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