Browse Source

Finished Assignment

Peter McCormick 6 years ago
parent
commit
e7f01fcfc9

+ 14
- 13
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

1
 package com.zipcodewilmington.danny_do_better_exercises;
1
 package com.zipcodewilmington.danny_do_better_exercises;
2
 
2
 
3
+import java.util.Arrays;
4
+
3
 /**
5
 /**
4
  * Created by dan on 6/14/17.
6
  * Created by dan on 6/14/17.
5
  */
7
  */
59
      * @return the middle character of `inputValue`
61
      * @return the middle character of `inputValue`
60
      */
62
      */
61
     public static Character getMiddleCharacter(String inputValue){
63
     public static Character getMiddleCharacter(String inputValue){
62
-        String outputValue = inputValue;
63
-        int position;
64
-        if(inputValue.length() %2 == 0) {
65
-            position = inputValue.length() / 2 -1;
66
-            return outputValue();
67
-        }else {
68
-            position = inputValue.length()/ 2;
69
-        }
70
-        return
71
-
64
+        int lenWord = inputValue.length()-1;
65
+        int midChar = (int)(Math.floor(lenWord/2));
66
+        return inputValue.charAt(midChar);
72
     }
67
     }
73
 
68
 
74
     /**
69
     /**
76
      * @return the first sequence of characters
71
      * @return the first sequence of characters
77
      */
72
      */
78
     public static String getFirstWord(String spaceDelimitedString){
73
     public static String getFirstWord(String spaceDelimitedString){
79
-        return null;
74
+        String words = spaceDelimitedString;
75
+        String[] splitString = spaceDelimitedString.trim().split("\\s+");
76
+        return splitString[0];
80
     }
77
     }
81
 
78
 
82
     /**
79
     /**
84
      * @return the second word of a string delimited by spaces.
81
      * @return the second word of a string delimited by spaces.
85
      */
82
      */
86
     public static String getSecondWord(String spaceDelimitedString){
83
     public static String getSecondWord(String spaceDelimitedString){
87
-        return null;
84
+
85
+        String[] words = spaceDelimitedString.trim().split(" ");
86
+        String second = words[1];
87
+        return second;
88
+
88
     }
89
     }
89
 
90
 
90
     /**
91
     /**
92
      * @return an identical string with characters in reverse order.
93
      * @return an identical string with characters in reverse order.
93
      */
94
      */
94
     public static String reverseTheTwo(String stringToReverse){
95
     public static String reverseTheTwo(String stringToReverse){
95
-        return null;
96
+       return new StringBuilder(stringToReverse).reverse().toString();
96
     }
97
     }
97
 }
98
 }

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

155
         String expected = "Wilmington";
155
         String expected = "Wilmington";
156
 
156
 
157
         // : When
157
         // : When
158
-        String actual = StringUtilities.getFirstWord(input);
158
+        String actual = StringUtilities.getSecondWord(input);
159
 
159
 
160
         // : Then
160
         // : Then
161
         assertEquals(expected, actual);
161
         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