Ver código fonte

I am finished

Ahson Chaudhary 6 anos atrás
pai
commit
237ed3e7a0

+ 2
- 0
ChapterOneMicro.iml Ver arquivo

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

+ 50
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Ver arquivo

@@ -11,7 +11,8 @@ 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
+
15
+        return baseValue + difference;
15 16
     }
16 17
 
17 18
     /**
@@ -20,7 +21,7 @@ public class MathUtilities {
20 21
      * @return sum of `baseValue` and `difference`
21 22
      */
22 23
     public Long add(long baseValue, long difference) {
23
-        return null;
24
+        return baseValue + difference;
24 25
     }
25 26
 
26 27
     /**
@@ -29,7 +30,8 @@ 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
+        return (short)(baseValue + difference);
33 35
     }
34 36
 
35 37
     /**
@@ -38,7 +40,7 @@ public class MathUtilities {
38 40
      * @return sum of `baseValue` and `difference`
39 41
      */
40 42
     public Byte add(byte baseValue, byte difference) {
41
-        return null;
43
+        return (byte)(baseValue + difference);
42 44
     }
43 45
 
44 46
     /**
@@ -47,7 +49,8 @@ public class MathUtilities {
47 49
      * @return sum of `baseValue` and `difference`
48 50
      */
49 51
     public Float add(float baseValue, float difference) {
50
-        return null;
52
+
53
+        return baseValue + difference;
51 54
     }
52 55
 
53 56
     /**
@@ -56,7 +59,8 @@ public class MathUtilities {
56 59
      * @return sum of `baseValue` and `difference`
57 60
      */
58 61
     public Double add(double baseValue, double difference) {
59
-        return null;
62
+
63
+        return baseValue + difference;
60 64
     }
61 65
 
62 66
     /**
@@ -65,7 +69,8 @@ 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
+
73
+        return baseValue - difference;
69 74
     }
70 75
 
71 76
     /**
@@ -74,7 +79,8 @@ public class MathUtilities {
74 79
      * @return difference between `baseValue` and `difference`
75 80
      */
76 81
     public Long subtract(long baseValue, long difference) {
77
-        return null;
82
+
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
+
93
+        return (short)(baseValue - difference);
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
+
103
+        return (byte)(baseValue - difference);
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
+
113
+        return baseValue - difference;
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
+
123
+        return baseValue - difference;
114 124
     }
115 125
 
116 126
 
@@ -120,7 +130,8 @@ 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
+
134
+        return dividend / divisor;
124 135
     }
125 136
 
126 137
     /**
@@ -129,7 +140,8 @@ public class MathUtilities {
129 140
      * @return division of `dividend` by `divisor
130 141
      */
131 142
     public Long divide(long dividend, long divisor) {
132
-        return null;
143
+
144
+        return dividend / divisor;
133 145
     }
134 146
 
135 147
     /**
@@ -138,7 +150,8 @@ public class MathUtilities {
138 150
      * @return division of `dividend` by `divisor
139 151
      */
140 152
     public Short divide(short dividend, short divisor) {
141
-        return null;
153
+
154
+        return (short)(dividend / divisor);
142 155
     }
143 156
 
144 157
     /**
@@ -147,7 +160,8 @@ public class MathUtilities {
147 160
      * @return division of `dividend` by `divisor
148 161
      */
149 162
     public Byte divide(byte dividend, byte divisor) {
150
-        return null;
163
+
164
+        return (byte)(dividend / divisor);
151 165
     }
152 166
 
153 167
     /**
@@ -156,7 +170,8 @@ public class MathUtilities {
156 170
      * @return division of `dividend` by `divisor
157 171
      */
158 172
     public Float divide(float dividend, float divisor) {
159
-        return null;
173
+
174
+        return dividend / divisor;
160 175
     }
161 176
 
162 177
     /**
@@ -165,7 +180,8 @@ public class MathUtilities {
165 180
      * @return division of `dividend` by `divisor
166 181
      */
167 182
     public Double divide(double dividend, double divisor) {
168
-        return null;
183
+
184
+        return dividend / divisor;
169 185
     }
170 186
 
171 187
 
@@ -175,7 +191,8 @@ public class MathUtilities {
175 191
      * @return product of `multiplicand` by `multiplier`
176 192
      */
177 193
     public Integer multiply(int multiplicand, int multiplier) {
178
-        return null;
194
+
195
+        return multiplicand * multiplier;
179 196
     }
180 197
 
181 198
     /**
@@ -184,7 +201,8 @@ public class MathUtilities {
184 201
      * @return product of `multiplicand` by `multiplier`
185 202
      */
186 203
     public Long multiply(long multiplicand, long multiplier) {
187
-        return null;
204
+
205
+        return multiplicand * multiplier;
188 206
     }
189 207
 
190 208
     /**
@@ -193,7 +211,8 @@ public class MathUtilities {
193 211
      * @return product of `multiplicand` by `multiplier`
194 212
      */
195 213
     public Short multiply(short multiplicand, short multiplier) {
196
-        return null;
214
+
215
+        return (short)(multiplicand * multiplier);
197 216
     }
198 217
     /**
199 218
      * @param multiplicand value to be multiplied
@@ -201,7 +220,8 @@ public class MathUtilities {
201 220
      * @return product of `multiplicand` by `multiplier`
202 221
      */
203 222
     public Byte multiply(byte multiplicand, byte multiplier) {
204
-        return null;
223
+
224
+        return (byte)(multiplicand * multiplier);
205 225
     }
206 226
 
207 227
     /**
@@ -210,7 +230,8 @@ public class MathUtilities {
210 230
      * @return product of `multiplicand` by `multiplier`
211 231
      */
212 232
     public Float multiply(float multiplicand, float multiplier) {
213
-        return null;
233
+
234
+        return multiplicand * multiplier;
214 235
     }
215 236
 
216 237
     /**
@@ -219,7 +240,8 @@ public class MathUtilities {
219 240
      * @return product of `multiplicand` by `multiplier`
220 241
      */
221 242
     public Double multiply(double multiplicand, double multiplier) {
222
-        return null;
243
+
244
+        return multiplicand * multiplier;
223 245
     }
224 246
 
225 247
 
@@ -227,14 +249,16 @@ public class MathUtilities {
227 249
       * @return true
228 250
      */
229 251
     public Boolean returnTrue() {
230
-        return null;
252
+
253
+        return true;
231 254
     }
232 255
 
233 256
     /**
234 257
      * @return false
235 258
      */
236 259
     public Boolean returnFalse() {
237
-        return null;
260
+
261
+        return false;
238 262
     }
239 263
 
240 264
 }

+ 29
- 5
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Ver arquivo

@@ -10,16 +10,26 @@ 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
+        else{
17
+            return false;
18
+        }
14 19
     }
15
-
16 20
     /**
17 21
      * @param x
18 22
      * @param y
19 23
      * @return true if `x` is less than `y`
20 24
      */
21 25
     public Boolean isLessThan(int x, int y) {
22
-        return null;
26
+        if (x < y){
27
+            return true;
28
+        }
29
+        else{
30
+            return false;
31
+        }
32
+
23 33
     }
24 34
 
25 35
     /**
@@ -28,7 +38,15 @@ public class PredicateUtilities {
28 38
      * @return true if `x` is greater than or equal to `y`
29 39
      */
30 40
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
41
+        if (x >= y) {
42
+
43
+            return true;
44
+
45
+        }
46
+
47
+        else {
48
+            return false;
49
+        }
32 50
     }
33 51
 
34 52
     /**
@@ -37,6 +55,12 @@ public class PredicateUtilities {
37 55
      * @return true if `x` is less than or equal to `y`
38 56
      */
39 57
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
58
+        if (x <= y){
59
+            return true;
60
+        }
61
+
62
+        else{
63
+            return false;
64
+        }
41 65
     }
42 66
 }

+ 56
- 11
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Ver arquivo

@@ -1,5 +1,7 @@
1 1
 package com.zipcodewilmington.danny_do_better_exercises;
2 2
 
3
+import com.sun.xml.internal.fastinfoset.util.CharArray;
4
+
3 5
 /**
4 6
  * Created by dan on 6/14/17.
5 7
  */
@@ -8,7 +10,9 @@ public class StringUtilities {
8 10
      * @return `Hello World` as a string
9 11
      */
10 12
     public static String getHelloWorld() {
11
-        return null;
13
+
14
+
15
+        return "Hello World";
12 16
     }
13 17
 
14 18
     /**
@@ -17,7 +21,8 @@ public class StringUtilities {
17 21
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 22
      */
19 23
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
24
+
25
+        return firstSegment + secondSegment;
21 26
     }
22 27
 
23 28
     /**
@@ -26,7 +31,8 @@ public class StringUtilities {
26 31
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 32
      */
28 33
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
34
+
35
+        return firstSegment + secondSegment;
30 36
     }
31 37
 
32 38
     /**
@@ -34,7 +40,8 @@ public class StringUtilities {
34 40
      * @return the first 3 characters of `input`
35 41
      */
36 42
     public static String getPrefix(String input){
37
-        return null;
43
+
44
+        return input.substring(0, 3);
38 45
     }
39 46
 
40 47
     /**
@@ -42,7 +49,8 @@ public class StringUtilities {
42 49
      * @return the last 3 characters of `input`
43 50
      */
44 51
     public static String getSuffix(String input){
45
-        return null;
52
+
53
+        return input.substring(input.length() - 3);
46 54
     }
47 55
 
48 56
     /**
@@ -51,7 +59,8 @@ public class StringUtilities {
51 59
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 60
      */
53 61
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
62
+
63
+        return false;
55 64
     }
56 65
 
57 66
     /**
@@ -59,7 +68,20 @@ public class StringUtilities {
59 68
      * @return the middle character of `inputValue`
60 69
      */
61 70
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
71
+
72
+        double splitWord = inputValue.length() / 2;
73
+        int m = (int)splitWord;
74
+
75
+        if (inputValue.length()% 2 != 0)
76
+        {
77
+            return inputValue.charAt(m);
78
+        }
79
+        else{
80
+
81
+            return inputValue.charAt(m - 1);
82
+
83
+        }
84
+
63 85
     }
64 86
 
65 87
     /**
@@ -67,15 +89,28 @@ public class StringUtilities {
67 89
      * @return the first sequence of characters
68 90
      */
69 91
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
92
+
93
+        for (int i = 0; i < spaceDelimitedString.length(); i++)
94
+        {
95
+            if(spaceDelimitedString.charAt(i) == ' ')
96
+            {
97
+                return spaceDelimitedString.substring(0, i);
98
+
99
+            }
100
+
101
+        }return null;
71 102
     }
72 103
 
73 104
     /**
74 105
      * @param spaceDelimitedString a string delimited by spaces
75 106
      * @return the second word of a string delimited by spaces.
76 107
      */
77
-    public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
108
+    public static String getSecondWord(String spaceDelimitedString)
109
+    {
110
+        String [ ] splitArray = spaceDelimitedString.split(" ");
111
+
112
+        return splitArray[1];
113
+
79 114
     }
80 115
 
81 116
     /**
@@ -83,6 +118,16 @@ public class StringUtilities {
83 118
      * @return an identical string with characters in reverse order.
84 119
      */
85 120
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
121
+
122
+        String reverseTheString = "";
123
+
124
+        char [] charArray = stringToReverse.toCharArray();
125
+
126
+        for (int i = charArray.length - 1; i >= 0; i--)
127
+        {
128
+            reverseTheString += charArray[i];
129
+
130
+        }
131
+        return reverseTheString;
87 132
     }
88 133
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Ver arquivo

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

+ 5
- 5
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Ver arquivo

@@ -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() {
@@ -295,8 +295,8 @@ public class TestMathUtilities {
295 295
     public void testMultiplication3() {
296 296
         // : Given
297 297
         byte multiplicand = 16;
298
-        byte multiplier = 14;
299
-        byte expectedByte = 64;
298
+        byte multiplier = -2;
299
+        byte expectedByte = -32;
300 300
         // : When
301 301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
302 302
         // : Then
@@ -311,7 +311,7 @@ public class TestMathUtilities {
311 311
         // : When
312 312
         float actualFloat =  primativeTypes.multiply(multiplicand,multiplier);
313 313
         // : Then
314
-        assertEquals(expectedFloat, actualFloat, 0);
314
+        assertEquals(expectedFloat, actualFloat, 0.003);
315 315
     }
316 316
     @Test
317 317
     public void testMultiplication5() {

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Ver arquivo

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


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Ver arquivo


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Ver arquivo


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Ver arquivo


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Ver arquivo