Eric Cordell пре 6 година
родитељ
комит
1cb1fbfd52

+ 2
- 0
ChapterOneMicro.iml Прегледај датотеку

@@ -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>

+ 44
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Прегледај датотеку

@@ -5,13 +5,15 @@ package com.zipcodewilmington.danny_do_better_exercises;
5 5
  */
6 6
 public class MathUtilities {
7 7
 
8
+    private short baseValue;
9
+
8 10
     /**
9 11
      * @param baseValue  starting value
10 12
      * @param difference value to add to starting value
11 13
      * @return sum of `baseValue` and `difference`
12 14
      */
13 15
     public Integer add(int baseValue, int difference) {
14
-        return null;
16
+        return baseValue + difference;
15 17
     }
16 18
 
17 19
     /**
@@ -20,7 +22,7 @@ public class MathUtilities {
20 22
      * @return sum of `baseValue` and `difference`
21 23
      */
22 24
     public Long add(long baseValue, long difference) {
23
-        return null;
25
+        return baseValue + difference;
24 26
     }
25 27
 
26 28
     /**
@@ -29,7 +31,8 @@ public class MathUtilities {
29 31
      * @return sum of `baseValue` and `difference`
30 32
      */
31 33
     public Short add(short baseValue, short difference) {
32
-        return null;
34
+        short sum = (short) (baseValue + difference);
35
+        return sum;
33 36
     }
34 37
 
35 38
     /**
@@ -38,7 +41,8 @@ public class MathUtilities {
38 41
      * @return sum of `baseValue` and `difference`
39 42
      */
40 43
     public Byte add(byte baseValue, byte difference) {
41
-        return null;
44
+        byte sum = (byte) (baseValue + difference);
45
+        return sum;
42 46
     }
43 47
 
44 48
     /**
@@ -47,7 +51,8 @@ public class MathUtilities {
47 51
      * @return sum of `baseValue` and `difference`
48 52
      */
49 53
     public Float add(float baseValue, float difference) {
50
-        return null;
54
+        float sum = (float) (baseValue + difference);
55
+        return sum;
51 56
     }
52 57
 
53 58
     /**
@@ -56,7 +61,8 @@ public class MathUtilities {
56 61
      * @return sum of `baseValue` and `difference`
57 62
      */
58 63
     public Double add(double baseValue, double difference) {
59
-        return null;
64
+        double sum = (double) (baseValue + difference);
65
+        return sum;
60 66
     }
61 67
 
62 68
     /**
@@ -65,7 +71,7 @@ public class MathUtilities {
65 71
      * @return difference between `baseValue` and `difference`
66 72
      */
67 73
     public Integer subtract(int baseValue, int difference) {
68
-        return null;
74
+        return baseValue - difference;
69 75
     }
70 76
 
71 77
     /**
@@ -74,7 +80,7 @@ public class MathUtilities {
74 80
      * @return difference between `baseValue` and `difference`
75 81
      */
76 82
     public Long subtract(long baseValue, long difference) {
77
-        return null;
83
+        return baseValue - difference;
78 84
     }
79 85
 
80 86
     /**
@@ -83,7 +89,8 @@ public class MathUtilities {
83 89
      * @return difference between `baseValue` and `difference`
84 90
      */
85 91
     public Short subtract(short baseValue, short difference) {
86
-        return null;
92
+        short sum = (short) (baseValue - difference);
93
+        return sum;
87 94
     }
88 95
 
89 96
     /**
@@ -92,7 +99,8 @@ public class MathUtilities {
92 99
      * @return difference between `baseValue` and `difference`
93 100
      */
94 101
     public Byte subtract(byte baseValue, byte difference) {
95
-        return null;
102
+        byte sum = (byte) (baseValue - difference);
103
+        return sum;
96 104
     }
97 105
 
98 106
     /**
@@ -101,7 +109,8 @@ public class MathUtilities {
101 109
      * @return difference between `baseValue` and `difference`
102 110
      */
103 111
     public Float subtract(float baseValue, float difference) {
104
-        return null;
112
+        float sum = (float) baseValue - difference;
113
+        return sum;
105 114
     }
106 115
 
107 116
     /**
@@ -110,7 +119,8 @@ public class MathUtilities {
110 119
      * @return difference between `baseValue` and `difference`
111 120
      */
112 121
     public Double subtract(double baseValue, double difference) {
113
-        return null;
122
+        double sum = (double) (baseValue - difference);
123
+        return sum;
114 124
     }
115 125
 
116 126
 
@@ -120,7 +130,7 @@ public class MathUtilities {
120 130
      * @return division of `dividend` by `divisor
121 131
      */
122 132
     public Integer divide(int dividend, int divisor) {
123
-        return null;
133
+        return dividend / divisor;
124 134
     }
125 135
 
126 136
     /**
@@ -129,7 +139,7 @@ public class MathUtilities {
129 139
      * @return division of `dividend` by `divisor
130 140
      */
131 141
     public Long divide(long dividend, long divisor) {
132
-        return null;
142
+        return dividend / divisor;
133 143
     }
134 144
 
135 145
     /**
@@ -138,7 +148,8 @@ public class MathUtilities {
138 148
      * @return division of `dividend` by `divisor
139 149
      */
140 150
     public Short divide(short dividend, short divisor) {
141
-        return null;
151
+        short sum = (short) (dividend / divisor);
152
+        return sum;
142 153
     }
143 154
 
144 155
     /**
@@ -147,7 +158,8 @@ public class MathUtilities {
147 158
      * @return division of `dividend` by `divisor
148 159
      */
149 160
     public Byte divide(byte dividend, byte divisor) {
150
-        return null;
161
+        byte sum = (byte) (dividend / divisor);
162
+        return sum;
151 163
     }
152 164
 
153 165
     /**
@@ -156,7 +168,8 @@ public class MathUtilities {
156 168
      * @return division of `dividend` by `divisor
157 169
      */
158 170
     public Float divide(float dividend, float divisor) {
159
-        return null;
171
+        float sum = (float) (dividend / divisor);
172
+        return sum;
160 173
     }
161 174
 
162 175
     /**
@@ -165,7 +178,8 @@ public class MathUtilities {
165 178
      * @return division of `dividend` by `divisor
166 179
      */
167 180
     public Double divide(double dividend, double divisor) {
168
-        return null;
181
+        double sum = (double) (dividend / divisor);
182
+        return sum;
169 183
     }
170 184
 
171 185
 
@@ -175,7 +189,7 @@ public class MathUtilities {
175 189
      * @return product of `multiplicand` by `multiplier`
176 190
      */
177 191
     public Integer multiply(int multiplicand, int multiplier) {
178
-        return null;
192
+        return multiplicand * multiplier;
179 193
     }
180 194
 
181 195
     /**
@@ -184,7 +198,7 @@ public class MathUtilities {
184 198
      * @return product of `multiplicand` by `multiplier`
185 199
      */
186 200
     public Long multiply(long multiplicand, long multiplier) {
187
-        return null;
201
+        return multiplicand * multiplier;
188 202
     }
189 203
 
190 204
     /**
@@ -193,7 +207,8 @@ public class MathUtilities {
193 207
      * @return product of `multiplicand` by `multiplier`
194 208
      */
195 209
     public Short multiply(short multiplicand, short multiplier) {
196
-        return null;
210
+        short sum = (short) (multiplicand * multiplier);
211
+        return sum;
197 212
     }
198 213
     /**
199 214
      * @param multiplicand value to be multiplied
@@ -201,7 +216,8 @@ public class MathUtilities {
201 216
      * @return product of `multiplicand` by `multiplier`
202 217
      */
203 218
     public Byte multiply(byte multiplicand, byte multiplier) {
204
-        return null;
219
+        byte sum = (byte) (multiplicand * multiplier);
220
+        return sum;
205 221
     }
206 222
 
207 223
     /**
@@ -210,7 +226,8 @@ public class MathUtilities {
210 226
      * @return product of `multiplicand` by `multiplier`
211 227
      */
212 228
     public Float multiply(float multiplicand, float multiplier) {
213
-        return null;
229
+        float sum = (float) (multiplicand * multiplier);
230
+        return sum;
214 231
     }
215 232
 
216 233
     /**
@@ -219,7 +236,8 @@ public class MathUtilities {
219 236
      * @return product of `multiplicand` by `multiplier`
220 237
      */
221 238
     public Double multiply(double multiplicand, double multiplier) {
222
-        return null;
239
+        double sum = (double) (multiplicand * multiplier);
240
+        return sum;
223 241
     }
224 242
 
225 243
 
@@ -227,14 +245,14 @@ public class MathUtilities {
227 245
       * @return true
228 246
      */
229 247
     public Boolean returnTrue() {
230
-        return null;
248
+        return true;
231 249
     }
232 250
 
233 251
     /**
234 252
      * @return false
235 253
      */
236 254
     public Boolean returnFalse() {
237
-        return null;
255
+        return false;
238 256
     }
239 257
 
240 258
 }

+ 16
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Прегледај датотеку

@@ -10,7 +10,10 @@ 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
+        if (x > y) {
14
+            return true;
15
+        }
16
+        return false;
14 17
     }
15 18
 
16 19
     /**
@@ -19,7 +22,10 @@ public class PredicateUtilities {
19 22
      * @return true if `x` is less than `y`
20 23
      */
21 24
     public Boolean isLessThan(int x, int y) {
22
-        return null;
25
+        if (x < y) {
26
+            return true;
27
+        }
28
+        return false;
23 29
     }
24 30
 
25 31
     /**
@@ -28,7 +34,10 @@ public class PredicateUtilities {
28 34
      * @return true if `x` is greater than or equal to `y`
29 35
      */
30 36
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
37
+        if (x >= y) {
38
+            return true;
39
+        }
40
+        return false;
32 41
     }
33 42
 
34 43
     /**
@@ -37,6 +46,9 @@ public class PredicateUtilities {
37 46
      * @return true if `x` is less than or equal to `y`
38 47
      */
39 48
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
49
+        if (x <= y) {
50
+            return true;
51
+        }
52
+        return false;
41 53
     }
42 54
 }

+ 29
- 10
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Прегледај датотеку

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

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Прегледај датотеку

@@ -5,6 +5,6 @@ package com.zipcodewilmington.danny_do_better_exercises;
5 5
  */
6 6
 public class ZipcodeRocks {
7 7
     public static void main(String[] args) {
8
-//         System.out.println("Zipcode Rocks!");
8
+         System.out.println("Zipcode Rocks!");
9 9
     }
10 10
 }

+ 13
- 5
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Прегледај датотеку

@@ -36,11 +36,19 @@ public class TestMathUtilities {
36 36
         // : Given
37 37
         short baseValue = 16384;
38 38
         short addedValue = 7;
39
-        short expected = 32767;
39
+        short expected = 16391;
40 40
         // : When
41
-        short actual = primativeTypes.add(baseValue, addedValue);
41
+        short actual = (short) primativeTypes.add(baseValue, addedValue);
42 42
         // : Then
43 43
         assertEquals(expected,actual);
44
+
45
+        // : Given
46
+        short baseValue1 = 32000;
47
+        short addedValue1 = 32000;
48
+        // : When
49
+        short actual1 = (short) primativeTypes.add(baseValue1, addedValue1);
50
+        // : Then
51
+        System.out.println(actual1);
44 52
     }
45 53
 
46 54
     @Test
@@ -142,7 +150,7 @@ public class TestMathUtilities {
142 150
         // : Given
143 151
         float baseValue = 750.585F;
144 152
         float difference = 795.0F;
145
-        float expectedFloat = -44.415F;
153
+        float expectedFloat = -44.414978F;
146 154
         // : When
147 155
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148 156
         // : Then
@@ -294,8 +302,8 @@ public class TestMathUtilities {
294 302
     @Test
295 303
     public void testMultiplication3() {
296 304
         // : Given
297
-        byte multiplicand = 16;
298
-        byte multiplier = 14;
305
+        byte multiplicand = 8;
306
+        byte multiplier = 8;
299 307
         byte expectedByte = 64;
300 308
         // : When
301 309
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Прегледај датотеку

@@ -26,7 +26,7 @@ public class TestPredicateUtilities {
26 26
     @Test
27 27
     public void testGreaterThanFalse(){
28 28
         // : Given
29
-        int greaterValue = 350;
29
+        int greaterValue = 351;
30 30
         int lesserValue = 350;
31 31
 
32 32
         // : When
@@ -56,7 +56,7 @@ public class TestPredicateUtilities {
56 56
     public void testLessThan1(){
57 57
         // : Given
58 58
         int greaterValue = 450;
59
-        int lesserValue = 350;
59
+        int lesserValue = 550;
60 60
 
61 61
         // : When
62 62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
@@ -109,7 +109,7 @@ public class TestPredicateUtilities {
109 109
     @Test
110 110
     public void testGreaterOrEqual2(){
111 111
         // : Given
112
-        int greaterValue = 8;
112
+        int greaterValue = 18;
113 113
         int lesserValue = 15;
114 114
 
115 115
         // : When

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Прегледај датотеку

@@ -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 = "Hel";
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 Прегледај датотеку


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Прегледај датотеку


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Прегледај датотеку


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Прегледај датотеку


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Прегледај датотеку


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Прегледај датотеку


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Прегледај датотеку