Browse Source

Finally done Project

Corinne Winarski 6 years ago
parent
commit
b38fa9a4de

+ 1
- 1
.idea/misc.xml View File

23
       </profile-state>
23
       </profile-state>
24
     </entry>
24
     </entry>
25
   </component>
25
   </component>
26
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
26
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="9.0" project-jdk-type="JavaSDK">
27
     <output url="file://$PROJECT_DIR$/classes" />
27
     <output url="file://$PROJECT_DIR$/classes" />
28
   </component>
28
   </component>
29
   <component name="masterDetails">
29
   <component name="masterDetails">

+ 2
- 0
ChapterOneMicro.iml View File

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>

+ 55
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java View File

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

+ 23
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java View File

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

+ 38
- 10
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

8
      * @return `Hello World` as a string
8
      * @return `Hello World` as a string
9
      */
9
      */
10
     public static String getHelloWorld() {
10
     public static String getHelloWorld() {
11
-        return null;
11
+        return("Hello World");
12
     }
12
     }
13
 
13
 
14
     /**
14
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
18
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
19
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+
21
+        return(firstSegment + "" + secondSegment);
21
     }
22
     }
22
 
23
 
23
     /**
24
     /**
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
28
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
29
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
30
+
31
+       return(firstSegment + "" + secondSegment);
32
+
30
     }
33
     }
31
 
34
 
32
     /**
35
     /**
34
      * @return the first 3 characters of `input`
37
      * @return the first 3 characters of `input`
35
      */
38
      */
36
     public static String getPrefix(String input){
39
     public static String getPrefix(String input){
37
-        return null;
40
+
41
+         String userin = input;
42
+         String f =userin.substring(0,3);
43
+         return f;
44
+
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
+        String greeting = input;
53
+        String s = greeting.substring(2, 5);
54
+        return s;
46
     }
55
     }
47
 
56
 
48
     /**
57
     /**
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
60
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
61
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
62
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
63
+        String input = inputValue;
64
+        String compare = comparableValue;
65
+
66
+        boolean  equals = input.equals(compare);
67
+        return equals;
68
+
69
+
55
     }
70
     }
56
 
71
 
57
     /**
72
     /**
59
      * @return the middle character of `inputValue`
74
      * @return the middle character of `inputValue`
60
      */
75
      */
61
     public static Character getMiddleCharacter(String inputValue){
76
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
77
+        if (inputValue.length() % 2 == 0){
78
+            return inputValue.charAt((inputValue.length()/2) -1);
79
+
80
+        }else {
81
+        return inputValue.charAt(inputValue.length()/2);
82
+        }
83
+
84
+
85
+
63
     }
86
     }
64
 
87
 
65
     /**
88
     /**
67
      * @return the first sequence of characters
90
      * @return the first sequence of characters
68
      */
91
      */
69
     public static String getFirstWord(String spaceDelimitedString){
92
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
93
+    String[]  space  = spaceDelimitedString.split(" ");
94
+    return space[0];
71
     }
95
     }
72
 
96
 
73
     /**
97
     /**
75
      * @return the second word of a string delimited by spaces.
99
      * @return the second word of a string delimited by spaces.
76
      */
100
      */
77
     public static String getSecondWord(String spaceDelimitedString){
101
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
102
+
103
+        String[]  space  = spaceDelimitedString.split(" ");
104
+        return space[1];
105
+
79
     }
106
     }
80
 
107
 
81
     /**
108
     /**
83
      * @return an identical string with characters in reverse order.
110
      * @return an identical string with characters in reverse order.
84
      */
111
      */
85
     public static String reverseTheTwo(String stringToReverse){
112
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
113
+         return new StringBuilder(stringToReverse).reverse().toString();
114
+
87
     }
115
     }
88
 }
116
 }

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

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
 }

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

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
43
-        assertEquals(expected,actual);
43
+         assertEquals(expected,actual);
44
     }
44
     }
45
 
45
 
46
     @Test
46
     @Test
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() {
296
         // : Given
296
         // : Given
297
         byte multiplicand = 16;
297
         byte multiplicand = 16;
298
         byte multiplier = 14;
298
         byte multiplier = 14;
299
-        byte expectedByte = 64;
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

+ 4
- 4
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java View File

16
 
16
 
17
 
17
 
18
         // : When
18
         // : When
19
-        boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
19
+        boolean outcome = math.isGreaterThan(greaterValue,lesserValue);
20
 
20
 
21
         // : Then
21
         // : Then
22
         assertTrue(outcome);
22
         assertTrue(outcome);
33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
34
 
34
 
35
         // : Then
35
         // : Then
36
-        assertTrue(outcome);
36
+        assertFalse(outcome);
37
     }
37
     }
38
 
38
 
39
 
39
 
62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
63
 
63
 
64
         // : Then
64
         // : Then
65
-        assertTrue(outcome);
65
+        assertFalse(outcome);
66
     }
66
     }
67
 
67
 
68
 
68
 
116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
117
 
117
 
118
         // : Then
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 View File

56
     public void substringBeginTest(){
56
     public void substringBeginTest(){
57
         // : Given
57
         // : Given
58
         String input = "Hello";
58
         String input = "Hello";
59
-        String expected = "olleH";
59
+        String expected = "Hel";
60
 
60
 
61
         // : When
61
         // : When
62
         String actual = StringUtilities.getPrefix(input);
62
         String actual = StringUtilities.getPrefix(input);
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 View File


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


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


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


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


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


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