Pārlūkot izejas kodu

Merge c649a2f5ccd8a44abe5804afe282470f4fd612ec into 913fc8b71dfcb9ab6e5834ab57b3411cc112752d

EricBarnaba 6 gadus atpakaļ
vecāks
revīzija
e187bd9682
Revīzijas autora e-pasts nav piesaistīts nevienam kontam

+ 2
- 0
ChapterOneMicro.iml Parādīt failu

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

+ 30
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Parādīt failu

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

+ 5
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Parādīt failu

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

+ 37
- 9
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Parādīt failu

@@ -8,7 +8,8 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public static String getHelloWorld() {
11
-        return null;
11
+
12
+        return "Hello World";
12 13
     }
13 14
 
14 15
     /**
@@ -17,7 +18,9 @@ public class StringUtilities {
17 18
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 19
      */
19 20
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
21
+        StringBuilder concat = new StringBuilder();
22
+        concat.append(firstSegment).append(secondSegment);
23
+        return concat.toString();
21 24
     }
22 25
 
23 26
     /**
@@ -26,7 +29,9 @@ public class StringUtilities {
26 29
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 30
      */
28 31
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
32
+        StringBuilder concat = new StringBuilder();
33
+        concat.append(firstSegment).append(secondSegment);
34
+        return concat.toString();
30 35
     }
31 36
 
32 37
     /**
@@ -34,7 +39,8 @@ public class StringUtilities {
34 39
      * @return the first 3 characters of `input`
35 40
      */
36 41
     public static String getPrefix(String input){
37
-        return null;
42
+
43
+        return input.substring(0,3);
38 44
     }
39 45
 
40 46
     /**
@@ -42,7 +48,8 @@ public class StringUtilities {
42 48
      * @return the last 3 characters of `input`
43 49
      */
44 50
     public static String getSuffix(String input){
45
-        return null;
51
+
52
+        return input.substring(input.length() - 3, input.length());
46 53
     }
47 54
 
48 55
     /**
@@ -51,7 +58,8 @@ public class StringUtilities {
51 58
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 59
      */
53 60
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
61
+
62
+        return inputValue.equals(comparableValue);
55 63
     }
56 64
 
57 65
     /**
@@ -59,7 +67,10 @@ public class StringUtilities {
59 67
      * @return the middle character of `inputValue`
60 68
      */
61 69
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
70
+        if (inputValue.length() % 2 == 0) {
71
+            return inputValue.charAt((inputValue.length() / 2) - 1);
72
+        }
73
+        return inputValue.charAt(inputValue.length() / 2);
63 74
     }
64 75
 
65 76
     /**
@@ -67,6 +78,13 @@ public class StringUtilities {
67 78
      * @return the first sequence of characters
68 79
      */
69 80
     public static String getFirstWord(String spaceDelimitedString){
81
+        for (int i = 0; i<spaceDelimitedString.length(); i++){
82
+            if (spaceDelimitedString.charAt(i) == ' '){
83
+                int chopper = i;
84
+                return spaceDelimitedString.substring(0, chopper);
85
+            }
86
+
87
+        }
70 88
         return null;
71 89
     }
72 90
 
@@ -75,7 +93,11 @@ public class StringUtilities {
75 93
      * @return the second word of a string delimited by spaces.
76 94
      */
77 95
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
96
+        int start = spaceDelimitedString.indexOf(' ') +1;
97
+        //I spent way too long on this because I was trying way to hard to do it with loops (see my code for getFirstWord)
98
+        //And I'm pretty sure this only works because the String in question only has 2 words.  But I'll take what I can get
99
+        return spaceDelimitedString.substring(start, spaceDelimitedString.length());
100
+
79 101
     }
80 102
 
81 103
     /**
@@ -83,6 +105,12 @@ public class StringUtilities {
83 105
      * @return an identical string with characters in reverse order.
84 106
      */
85 107
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
108
+        StringBuilder answer = new StringBuilder();
109
+        for (int i = stringToReverse.length() -1; i>=0; i--){
110
+            answer.append(stringToReverse.charAt(i));
111
+        }
112
+
113
+
114
+        return answer.toString();
87 115
     }
88 116
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Parādīt failu

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

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Parādīt failu

@@ -36,7 +36,7 @@ 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 41
         short actual = primativeTypes.add(baseValue, addedValue);
42 42
         // : Then
@@ -146,7 +146,7 @@ public class TestMathUtilities {
146 146
         // : When
147 147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148 148
         // : Then
149
-        assertEquals(expectedFloat,actualFloat, 0);
149
+        assertEquals(expectedFloat,actualFloat, 0.003);
150 150
     }
151 151
     @Test
152 152
     public void testSubtractions5() {
@@ -296,7 +296,7 @@ public class TestMathUtilities {
296 296
         // : Given
297 297
         byte multiplicand = 16;
298 298
         byte multiplier = 14;
299
-        byte expectedByte = 64;
299
+        byte expectedByte = -32;
300 300
         // : When
301 301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
302 302
         // : Then

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Parādīt failu

@@ -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 Parādīt failu

@@ -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ārs
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Parādīt failu


Binārs
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Parādīt failu


Binārs
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Parādīt failu


Binārs
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Parādīt failu


Binārs
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Parādīt failu


Binārs
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Parādīt failu


Binārs
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Parādīt failu