Parcourir la source

doesn't matter

Owen Murphy il y a 6 ans
Parent
révision
18bc2d26d0

+ 2
- 0
ChapterOneMicro.iml Voir le fichier

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

+ 1
- 0
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Voir le fichier

@@ -29,6 +29,7 @@ public class MathUtilities {
29 29
      * @return sum of `baseValue` and `difference`
30 30
      */
31 31
     public Short add(short baseValue, short difference) {
32
+
32 33
         return null;
33 34
     }
34 35
 

+ 4
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Voir le fichier

@@ -10,7 +10,7 @@ public class PredicateUtilities {
10 10
      * @return true if `x` is greater than `y`
11 11
      */
12 12
     public Boolean isGreaterThan(int x, int y) {
13
-        return null;
13
+        return x > y;
14 14
     }
15 15
 
16 16
     /**
@@ -19,7 +19,7 @@ public class PredicateUtilities {
19 19
      * @return true if `x` is less than `y`
20 20
      */
21 21
     public Boolean isLessThan(int x, int y) {
22
-        return null;
22
+        return x <y;
23 23
     }
24 24
 
25 25
     /**
@@ -28,7 +28,7 @@ public class PredicateUtilities {
28 28
      * @return true if `x` is greater than or equal to `y`
29 29
      */
30 30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
31
+        return x >= y;
32 32
     }
33 33
 
34 34
     /**
@@ -37,6 +37,6 @@ public class PredicateUtilities {
37 37
      * @return true if `x` is less than or equal to `y`
38 38
      */
39 39
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
40
+        return x <= y;
41 41
     }
42 42
 }

+ 30
- 10
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Voir le fichier

@@ -8,7 +8,7 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public static String getHelloWorld() {
11
-        return null;
11
+        return "Hello World";
12 12
     }
13 13
 
14 14
     /**
@@ -17,7 +17,7 @@ public class StringUtilities {
17 17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 18
      */
19 19
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+        return firstSegment + secondSegment;
21 21
     }
22 22
 
23 23
     /**
@@ -26,7 +26,8 @@ public class StringUtilities {
26 26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 27
      */
28 28
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
29
+
30
+        return firstSegment + secondSegment;
30 31
     }
31 32
 
32 33
     /**
@@ -34,7 +35,9 @@ public class StringUtilities {
34 35
      * @return the first 3 characters of `input`
35 36
      */
36 37
     public static String getPrefix(String input){
37
-        return null;
38
+       return input.substring(0, 3);
39
+
40
+
38 41
     }
39 42
 
40 43
     /**
@@ -42,7 +45,8 @@ public class StringUtilities {
42 45
      * @return the last 3 characters of `input`
43 46
      */
44 47
     public static String getSuffix(String input){
45
-        return null;
48
+        return input.substring(input.length() - 3);
49
+
46 50
     }
47 51
 
48 52
     /**
@@ -51,7 +55,8 @@ public class StringUtilities {
51 55
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 56
      */
53 57
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
58
+        return (inputValue.equals(comparableValue)) ;
59
+
55 60
     }
56 61
 
57 62
     /**
@@ -59,7 +64,15 @@ public class StringUtilities {
59 64
      * @return the middle character of `inputValue`
60 65
      */
61 66
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
67
+        if (inputValue.length() % 2 == 1){
68
+            int bob = inputValue.length()/2;
69
+            return inputValue.charAt(bob);
70
+        }
71
+        else {
72
+            int bob = (inputValue.length() - 1)/2;
73
+            return inputValue.charAt(bob);
74
+        }
75
+
63 76
     }
64 77
 
65 78
     /**
@@ -67,7 +80,9 @@ public class StringUtilities {
67 80
      * @return the first sequence of characters
68 81
      */
69 82
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
83
+        String[] splitStr = spaceDelimitedString.trim().split("\\s+");
84
+                return splitStr[0];
85
+
71 86
     }
72 87
 
73 88
     /**
@@ -75,7 +90,9 @@ public class StringUtilities {
75 90
      * @return the second word of a string delimited by spaces.
76 91
      */
77 92
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
93
+        String[] splitStr = spaceDelimitedString.trim().split("\\s+");
94
+        return splitStr[1];
95
+
79 96
     }
80 97
 
81 98
     /**
@@ -83,6 +100,9 @@ public class StringUtilities {
83 100
      * @return an identical string with characters in reverse order.
84 101
      */
85 102
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
103
+        String bob = stringToReverse;
104
+        return new StringBuilder(bob).reverse().toString();
105
+
106
+
87 107
     }
88 108
 }

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Voir le fichier

@@ -33,7 +33,7 @@ public class TestPredicateUtilities {
33 33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
34 34
 
35 35
         // : Then
36
-        assertTrue(outcome);
36
+        assertFalse(outcome);
37 37
     }
38 38
 
39 39
 
@@ -62,7 +62,7 @@ public class TestPredicateUtilities {
62 62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
63 63
 
64 64
         // : Then
65
-        assertTrue(outcome);
65
+        assertFalse(outcome);
66 66
     }
67 67
 
68 68
 
@@ -116,6 +116,6 @@ public class TestPredicateUtilities {
116 116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
117 117
 
118 118
         // : Then
119
-        assertTrue(outcome);
119
+        assertFalse(outcome);
120 120
     }
121 121
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Voir le fichier

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

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Voir le fichier


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Voir le fichier


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Voir le fichier


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Voir le fichier


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Voir le fichier