Selaa lähdekoodia

I am finished

Ahson Chaudhary 6 vuotta sitten
vanhempi
commit
237ed3e7a0

+ 2
- 0
ChapterOneMicro.iml Näytä tiedosto

12
     <orderEntry type="sourceFolder" forTests="false" />
12
     <orderEntry type="sourceFolder" forTests="false" />
13
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
13
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
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
   </component>
17
   </component>
16
 </module>
18
 </module>

+ 50
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Näytä tiedosto

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

10
      * @return true if `x` is greater than `y`
10
      * @return true if `x` is greater than `y`
11
      */
11
      */
12
     public Boolean isGreaterThan(int x, int y) {
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
      * @param x
21
      * @param x
18
      * @param y
22
      * @param y
19
      * @return true if `x` is less than `y`
23
      * @return true if `x` is less than `y`
20
      */
24
      */
21
     public Boolean isLessThan(int x, int y) {
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
      * @return true if `x` is greater than or equal to `y`
38
      * @return true if `x` is greater than or equal to `y`
29
      */
39
      */
30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
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
      * @return true if `x` is less than or equal to `y`
55
      * @return true if `x` is less than or equal to `y`
38
      */
56
      */
39
     public Boolean isLessThanOrEqualTo(int x, int y) {
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 Näytä tiedosto

1
 package com.zipcodewilmington.danny_do_better_exercises;
1
 package com.zipcodewilmington.danny_do_better_exercises;
2
 
2
 
3
+import com.sun.xml.internal.fastinfoset.util.CharArray;
4
+
3
 /**
5
 /**
4
  * Created by dan on 6/14/17.
6
  * Created by dan on 6/14/17.
5
  */
7
  */
8
      * @return `Hello World` as a string
10
      * @return `Hello World` as a string
9
      */
11
      */
10
     public static String getHelloWorld() {
12
     public static String getHelloWorld() {
11
-        return null;
13
+
14
+
15
+        return "Hello World";
12
     }
16
     }
13
 
17
 
14
     /**
18
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
21
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
22
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
23
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
24
+
25
+        return firstSegment + secondSegment;
21
     }
26
     }
22
 
27
 
23
     /**
28
     /**
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
31
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
32
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
33
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
34
+
35
+        return firstSegment + secondSegment;
30
     }
36
     }
31
 
37
 
32
     /**
38
     /**
34
      * @return the first 3 characters of `input`
40
      * @return the first 3 characters of `input`
35
      */
41
      */
36
     public static String getPrefix(String input){
42
     public static String getPrefix(String input){
37
-        return null;
43
+
44
+        return input.substring(0, 3);
38
     }
45
     }
39
 
46
 
40
     /**
47
     /**
42
      * @return the last 3 characters of `input`
49
      * @return the last 3 characters of `input`
43
      */
50
      */
44
     public static String getSuffix(String input){
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
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
59
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
60
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
61
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
62
+
63
+        return false;
55
     }
64
     }
56
 
65
 
57
     /**
66
     /**
59
      * @return the middle character of `inputValue`
68
      * @return the middle character of `inputValue`
60
      */
69
      */
61
     public static Character getMiddleCharacter(String inputValue){
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
      * @return the first sequence of characters
89
      * @return the first sequence of characters
68
      */
90
      */
69
     public static String getFirstWord(String spaceDelimitedString){
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
      * @param spaceDelimitedString a string delimited by spaces
105
      * @param spaceDelimitedString a string delimited by spaces
75
      * @return the second word of a string delimited by spaces.
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
      * @return an identical string with characters in reverse order.
118
      * @return an identical string with characters in reverse order.
84
      */
119
      */
85
     public static String reverseTheTwo(String stringToReverse){
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 Näytä tiedosto

5
  */
5
  */
6
 public class ZipcodeRocks {
6
 public class ZipcodeRocks {
7
     public static void main(String[] args) {
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 Näytä tiedosto

36
         // : Given
36
         // : Given
37
         short baseValue = 16384;
37
         short baseValue = 16384;
38
         short addedValue = 7;
38
         short addedValue = 7;
39
-        short expected = 32767;
39
+        short expected = 16391;
40
         // : When
40
         // : When
41
         short actual = primativeTypes.add(baseValue, addedValue);
41
         short actual = primativeTypes.add(baseValue, addedValue);
42
         // : Then
42
         // : Then
146
         // : When
146
         // : When
147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148
         // : Then
148
         // : Then
149
-        assertEquals(expectedFloat,actualFloat, 0);
149
+        assertEquals(expectedFloat,actualFloat, 0.003);
150
     }
150
     }
151
     @Test
151
     @Test
152
     public void testSubtractions5() {
152
     public void testSubtractions5() {
295
     public void testMultiplication3() {
295
     public void testMultiplication3() {
296
         // : Given
296
         // : Given
297
         byte multiplicand = 16;
297
         byte multiplicand = 16;
298
-        byte multiplier = 14;
299
-        byte expectedByte = 64;
298
+        byte multiplier = -2;
299
+        byte expectedByte = -32;
300
         // : When
300
         // : When
301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
302
         // : Then
302
         // : Then
311
         // : When
311
         // : When
312
         float actualFloat =  primativeTypes.multiply(multiplicand,multiplier);
312
         float actualFloat =  primativeTypes.multiply(multiplicand,multiplier);
313
         // : Then
313
         // : Then
314
-        assertEquals(expectedFloat, actualFloat, 0);
314
+        assertEquals(expectedFloat, actualFloat, 0.003);
315
     }
315
     }
316
     @Test
316
     @Test
317
     public void testMultiplication5() {
317
     public void testMultiplication5() {

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Näytä tiedosto

154
         String expected = "Wilmington";
154
         String expected = "Wilmington";
155
 
155
 
156
         // : When
156
         // : When
157
-        String actual = StringUtilities.getFirstWord(input);
157
+        String actual = StringUtilities.getSecondWord(input);
158
 
158
 
159
         // : Then
159
         // : Then
160
         assertEquals(expected, actual);
160
         assertEquals(expected, actual);

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Näytä tiedosto


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Näytä tiedosto


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Näytä tiedosto


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Näytä tiedosto


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Näytä tiedosto


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Näytä tiedosto