Bläddra i källkod

Commiting Changes for Lab

Garrett Arant 6 år sedan
förälder
incheckning
6e864645d1

+ 2
- 0
ChapterOneMicro.iml Visa fil

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

+ 39
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Visa fil

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

+ 7
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Visa fil

@@ -3,14 +3,16 @@ package com.zipcodewilmington.danny_do_better_exercises;
3 3
 /**
4 4
  * Created by dan on 6/14/17.
5 5
  */
6
+
6 7
 public class PredicateUtilities {
7 8
     /**
8 9
      * @param x
9 10
      * @param y
10 11
      * @return true if `x` is greater than `y`
11 12
      */
13
+
12 14
     public Boolean isGreaterThan(int x, int y) {
13
-        return null;
15
+        return x > y;
14 16
     }
15 17
 
16 18
     /**
@@ -19,7 +21,7 @@ public class PredicateUtilities {
19 21
      * @return true if `x` is less than `y`
20 22
      */
21 23
     public Boolean isLessThan(int x, int y) {
22
-        return null;
24
+        return x < y;
23 25
     }
24 26
 
25 27
     /**
@@ -28,7 +30,8 @@ public class PredicateUtilities {
28 30
      * @return true if `x` is greater than or equal to `y`
29 31
      */
30 32
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
33
+
34
+        return x >= y;
32 35
     }
33 36
 
34 37
     /**
@@ -37,6 +40,6 @@ public class PredicateUtilities {
37 40
      * @return true if `x` is less than or equal to `y`
38 41
      */
39 42
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
43
+        return x <= y;
41 44
     }
42 45
 }

+ 22
- 12
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Visa fil

@@ -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,8 @@ 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
+
22
+        return (firstSegment + secondSegment);
21 23
     }
22 24
 
23 25
     /**
@@ -26,7 +28,8 @@ public class StringUtilities {
26 28
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 29
      */
28 30
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
31
+
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
+
41
+        return input.substring(0,3);
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(input.length()-3);
46 51
     }
47 52
 
48 53
     /**
@@ -51,23 +56,26 @@ 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;
59
+
60
+        return inputValue.equals(comparableValue);
55 61
     }
56 62
 
57 63
     /**
58 64
      * @param inputValue the value input from user
59 65
      * @return the middle character of `inputValue`
60 66
      */
61
-    public static Character getMiddleCharacter(String inputValue){
62
-        return null;
63
-    }
67
+    public static Character getMiddleCharacter(String inputValue)
68
+
69
+        {
70
+            
71
+        }
64 72
 
65 73
     /**
66 74
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 75
      * @return the first sequence of characters
68 76
      */
69 77
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
78
+        return spaceDelimitedString.substring(spaceDelimitedString.lastIndexOf(" ")+1);
71 79
     }
72 80
 
73 81
     /**
@@ -75,7 +83,7 @@ public class StringUtilities {
75 83
      * @return the second word of a string delimited by spaces.
76 84
      */
77 85
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
86
+        return spaceDelimitedString.trim();
79 87
     }
80 88
 
81 89
     /**
@@ -83,6 +91,8 @@ public class StringUtilities {
83 91
      * @return an identical string with characters in reverse order.
84 92
      */
85 93
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
94
+        return new StringBuilder(stringToReverse).reverse().toString();
95
+
96
+
87 97
     }
88 98
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Visa fil

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

@@ -36,9 +36,9 @@ 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
-        short actual = primativeTypes.add(baseValue, addedValue);
41
+        short actual = (short) primativeTypes.add(baseValue, addedValue);
42 42
         // : Then
43 43
         assertEquals(expected,actual);
44 44
     }
@@ -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.005);
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 Visa fil

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

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Visa fil

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

Binär
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Visa fil


Binär
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Visa fil


Binär
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Visa fil


Binär
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Visa fil


Binär
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Visa fil


Binär
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Visa fil


Binär
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Visa fil