Keith Brinker 6 anni fa
parent
commit
c45b15b768

+ 0
- 61
.idea/misc.xml Vedi File

@@ -26,65 +26,4 @@
26 26
   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
27 27
     <output url="file://$PROJECT_DIR$/classes" />
28 28
   </component>
29
-  <component name="masterDetails">
30
-    <states>
31
-      <state key="GlobalLibrariesConfigurable.UI">
32
-        <settings>
33
-          <splitter-proportions>
34
-            <option name="proportions">
35
-              <list>
36
-                <option value="0.2" />
37
-              </list>
38
-            </option>
39
-          </splitter-proportions>
40
-        </settings>
41
-      </state>
42
-      <state key="JdkListConfigurable.UI">
43
-        <settings>
44
-          <last-edited>1.8</last-edited>
45
-          <splitter-proportions>
46
-            <option name="proportions">
47
-              <list>
48
-                <option value="0.2" />
49
-              </list>
50
-            </option>
51
-          </splitter-proportions>
52
-        </settings>
53
-      </state>
54
-      <state key="ProjectJDKs.UI">
55
-        <settings>
56
-          <last-edited>1.8</last-edited>
57
-          <splitter-proportions>
58
-            <option name="proportions">
59
-              <list>
60
-                <option value="0.2" />
61
-              </list>
62
-            </option>
63
-          </splitter-proportions>
64
-        </settings>
65
-      </state>
66
-      <state key="ProjectLibrariesConfigurable.UI">
67
-        <settings>
68
-          <splitter-proportions>
69
-            <option name="proportions">
70
-              <list>
71
-                <option value="0.2" />
72
-              </list>
73
-            </option>
74
-          </splitter-proportions>
75
-        </settings>
76
-      </state>
77
-      <state key="ScopeChooserConfigurable.UI">
78
-        <settings>
79
-          <splitter-proportions>
80
-            <option name="proportions">
81
-              <list>
82
-                <option value="0.2" />
83
-              </list>
84
-            </option>
85
-          </splitter-proportions>
86
-        </settings>
87
-      </state>
88
-    </states>
89
-  </component>
90 29
 </project>

+ 2
- 0
ChapterOneMicro.iml Vedi File

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

+ 54
- 28
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Vedi File

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

+ 17
- 5
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Vedi File

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

+ 28
- 12
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Vedi File

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

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Vedi File

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

+ 4
- 4
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Vedi File

@@ -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
@@ -142,7 +142,7 @@ public class TestMathUtilities {
142 142
         // : Given
143 143
         float baseValue = 750.585F;
144 144
         float difference = 795.0F;
145
-        float expectedFloat = -44.415F;
145
+        float expectedFloat = -44.414978F;
146 146
         // : When
147 147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148 148
         // : Then
@@ -294,8 +294,8 @@ public class TestMathUtilities {
294 294
     @Test
295 295
     public void testMultiplication3() {
296 296
         // : Given
297
-        byte multiplicand = 16;
298
-        byte multiplier = 14;
297
+        byte multiplicand = 8;
298
+        byte multiplier = 8;
299 299
         byte expectedByte = 64;
300 300
         // : When
301 301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Vedi File

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

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


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Vedi File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Vedi File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Vedi File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Vedi File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Vedi File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Vedi File