瀏覽代碼

Finally done Project

Corinne Winarski 6 年之前
父節點
當前提交
b38fa9a4de
共有 16 個檔案被更改,包括 130 行新增52 行删除
  1. 1
    1
      .idea/misc.xml
  2. 2
    0
      ChapterOneMicro.iml
  3. 55
    26
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java
  4. 23
    4
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java
  5. 38
    10
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java
  6. 1
    1
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java
  7. 4
    4
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java
  8. 4
    4
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java
  9. 2
    2
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java
  10. 二進制
      target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class
  11. 二進制
      target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class
  12. 二進制
      target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class
  13. 二進制
      target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class
  14. 二進制
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class
  15. 二進制
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class
  16. 二進制
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class

+ 1
- 1
.idea/misc.xml 查看文件

@@ -23,7 +23,7 @@
23 23
       </profile-state>
24 24
     </entry>
25 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 27
     <output url="file://$PROJECT_DIR$/classes" />
28 28
   </component>
29 29
   <component name="masterDetails">

+ 2
- 0
ChapterOneMicro.iml 查看文件

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

+ 55
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java 查看文件

@@ -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
+        int add = baseValue + difference;
15
+        return add;
15 16
     }
16 17
 
17 18
     /**
@@ -20,7 +21,9 @@ 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
+         long add = baseValue + difference;
25
+         return add;
26
+
24 27
     }
25 28
 
26 29
     /**
@@ -29,7 +32,8 @@ public class MathUtilities {
29 32
      * @return sum of `baseValue` and `difference`
30 33
      */
31 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,7 +42,8 @@ public class MathUtilities {
38 42
      * @return sum of `baseValue` and `difference`
39 43
      */
40 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,7 +52,8 @@ public class MathUtilities {
47 52
      * @return sum of `baseValue` and `difference`
48 53
      */
49 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,7 +62,9 @@ public class MathUtilities {
56 62
      * @return sum of `baseValue` and `difference`
57 63
      */
58 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,7 +73,9 @@ public class MathUtilities {
65 73
      * @return difference between `baseValue` and `difference`
66 74
      */
67 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,7 +84,10 @@ 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
+
88
+        long sub = baseValue - difference;
89
+        return sub;
90
+
78 91
     }
79 92
 
80 93
     /**
@@ -83,7 +96,8 @@ public class MathUtilities {
83 96
      * @return difference between `baseValue` and `difference`
84 97
      */
85 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,7 +106,8 @@ public class MathUtilities {
92 106
      * @return difference between `baseValue` and `difference`
93 107
      */
94 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,7 +116,8 @@ public class MathUtilities {
101 116
      * @return difference between `baseValue` and `difference`
102 117
      */
103 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,7 +126,8 @@ public class MathUtilities {
110 126
      * @return difference between `baseValue` and `difference`
111 127
      */
112 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,7 +137,8 @@ public class MathUtilities {
120 137
      * @return division of `dividend` by `divisor
121 138
      */
122 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,7 +147,8 @@ public class MathUtilities {
129 147
      * @return division of `dividend` by `divisor
130 148
      */
131 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,7 +157,8 @@ public class MathUtilities {
138 157
      * @return division of `dividend` by `divisor
139 158
      */
140 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,7 +167,8 @@ public class MathUtilities {
147 167
      * @return division of `dividend` by `divisor
148 168
      */
149 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,7 +177,8 @@ public class MathUtilities {
156 177
      * @return division of `dividend` by `divisor
157 178
      */
158 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,7 +187,8 @@ public class MathUtilities {
165 187
      * @return division of `dividend` by `divisor
166 188
      */
167 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,7 +198,8 @@ public class MathUtilities {
175 198
      * @return product of `multiplicand` by `multiplier`
176 199
      */
177 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,7 +208,8 @@ public class MathUtilities {
184 208
      * @return product of `multiplicand` by `multiplier`
185 209
      */
186 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,7 +218,8 @@ public class MathUtilities {
193 218
      * @return product of `multiplicand` by `multiplier`
194 219
      */
195 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 225
      * @param multiplicand value to be multiplied
@@ -201,7 +227,8 @@ public class MathUtilities {
201 227
      * @return product of `multiplicand` by `multiplier`
202 228
      */
203 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,7 +237,8 @@ public class MathUtilities {
210 237
      * @return product of `multiplicand` by `multiplier`
211 238
      */
212 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,7 +247,8 @@ public class MathUtilities {
219 247
      * @return product of `multiplicand` by `multiplier`
220 248
      */
221 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,14 +256,14 @@ public class MathUtilities {
227 256
       * @return true
228 257
      */
229 258
     public Boolean returnTrue() {
230
-        return null;
259
+        return true;
231 260
     }
232 261
 
233 262
     /**
234 263
      * @return false
235 264
      */
236 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 查看文件

@@ -10,7 +10,13 @@ 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
+
19
+        }
14 20
     }
15 21
 
16 22
     /**
@@ -19,7 +25,12 @@ public class PredicateUtilities {
19 25
      * @return true if `x` is less than `y`
20 26
      */
21 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,7 +39,11 @@ public class PredicateUtilities {
28 39
      * @return true if `x` is greater than or equal to `y`
29 40
      */
30 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,6 +52,10 @@ public class PredicateUtilities {
37 52
      * @return true if `x` is less than or equal to `y`
38 53
      */
39 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 查看文件

@@ -8,7 +8,7 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public static String getHelloWorld() {
11
-        return null;
11
+        return("Hello World");
12 12
     }
13 13
 
14 14
     /**
@@ -17,7 +17,8 @@ public class StringUtilities {
17 17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 18
      */
19 19
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+
21
+        return(firstSegment + "" + secondSegment);
21 22
     }
22 23
 
23 24
     /**
@@ -26,7 +27,9 @@ public class StringUtilities {
26 27
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 28
      */
28 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,7 +37,11 @@ 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
+         String userin = input;
42
+         String f =userin.substring(0,3);
43
+         return f;
44
+
38 45
     }
39 46
 
40 47
     /**
@@ -42,7 +49,9 @@ 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
+        String greeting = input;
53
+        String s = greeting.substring(2, 5);
54
+        return s;
46 55
     }
47 56
 
48 57
     /**
@@ -51,7 +60,13 @@ public class StringUtilities {
51 60
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 61
      */
53 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,7 +74,15 @@ public class StringUtilities {
59 74
      * @return the middle character of `inputValue`
60 75
      */
61 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,7 +90,8 @@ public class StringUtilities {
67 90
      * @return the first sequence of characters
68 91
      */
69 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,7 +99,10 @@ public class StringUtilities {
75 99
      * @return the second word of a string delimited by spaces.
76 100
      */
77 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,6 +110,7 @@ public class StringUtilities {
83 110
      * @return an identical string with characters in reverse order.
84 111
      */
85 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 查看文件

@@ -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 查看文件

@@ -36,11 +36,11 @@ 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
43
-        assertEquals(expected,actual);
43
+         assertEquals(expected,actual);
44 44
     }
45 45
 
46 46
     @Test
@@ -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() {
@@ -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

+ 4
- 4
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java 查看文件

@@ -16,7 +16,7 @@ public class TestPredicateUtilities {
16 16
 
17 17
 
18 18
         // : When
19
-        boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
19
+        boolean outcome = math.isGreaterThan(greaterValue,lesserValue);
20 20
 
21 21
         // : Then
22 22
         assertTrue(outcome);
@@ -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
 }

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java 查看文件

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

二進制
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class 查看文件


二進制
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class 查看文件


二進制
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class 查看文件


二進制
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class 查看文件


二進制
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class 查看文件


二進制
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class 查看文件


二進制
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class 查看文件