ソースを参照

Merge 68648331385e18131a0d1a58db30ad336710fca0 into 913fc8b71dfcb9ab6e5834ab57b3411cc112752d

gjarant 6 年 前
コミット
9f96098dd4
コミット者のEメールアドレスに関連付けられたアカウントが存在しません
共有15 個のファイルを変更した84 個の追加51 個の削除を含む
  1. 2
    0
      ChapterOneMicro.iml
  2. 39
    26
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java
  3. 7
    4
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java
  4. 27
    12
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java
  5. 1
    1
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java
  6. 4
    4
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java
  7. 3
    3
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java
  8. 1
    1
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java
  9. バイナリ
      target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class
  10. バイナリ
      target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class
  11. バイナリ
      target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class
  12. バイナリ
      target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class
  13. バイナリ
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class
  14. バイナリ
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class
  15. バイナリ
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class

+ 2
- 0
ChapterOneMicro.iml ファイルの表示

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>

+ 39
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java ファイルの表示

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

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

+ 27
- 12
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java ファイルの表示

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
+
12
+        return "Hello World";
12
     }
13
     }
13
 
14
 
14
     /**
15
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
19
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
20
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
21
+
22
+        return (firstSegment + secondSegment);
21
     }
23
     }
22
 
24
 
23
     /**
25
     /**
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
28
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
29
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
30
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
31
+
32
+        return (firstSegment + secondSegment);
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
+        return input.substring(0,3);
38
     }
42
     }
39
 
43
 
40
     /**
44
     /**
42
      * @return the last 3 characters of `input`
46
      * @return the last 3 characters of `input`
43
      */
47
      */
44
     public static String getSuffix(String input){
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
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
56
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
57
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
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
      * @param inputValue the value input from user
64
      * @param inputValue the value input from user
59
      * @return the middle character of `inputValue`
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
+            //Find length of the word
71
+            int lengthOfWord= inputValue.length()-1;
72
+            //Divide the length by 2, account for even;
73
+            int middleLengthOfWord= (int)(Math.floor(lengthOfWord/2));
74
+            return inputValue.charAt(middleLengthOfWord);
75
+
76
+        }
64
 
77
 
65
     /**
78
     /**
66
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
79
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67
      * @return the first sequence of characters
80
      * @return the first sequence of characters
68
      */
81
      */
69
     public static String getFirstWord(String spaceDelimitedString){
82
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
83
+        return spaceDelimitedString.substring(spaceDelimitedString.lastIndexOf(" ")+1);
71
     }
84
     }
72
 
85
 
73
     /**
86
     /**
75
      * @return the second word of a string delimited by spaces.
88
      * @return the second word of a string delimited by spaces.
76
      */
89
      */
77
     public static String getSecondWord(String spaceDelimitedString){
90
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
91
+        return spaceDelimitedString.trim();
79
     }
92
     }
80
 
93
 
81
     /**
94
     /**
83
      * @return an identical string with characters in reverse order.
96
      * @return an identical string with characters in reverse order.
84
      */
97
      */
85
     public static String reverseTheTwo(String stringToReverse){
98
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
99
+        return new StringBuilder(stringToReverse).reverse().toString();
100
+
101
+
87
     }
102
     }
88
 }
103
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java ファイルの表示

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 ファイルの表示

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

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java ファイルの表示

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
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java ファイルの表示

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

バイナリ
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 ファイルの表示