Procházet zdrojové kódy

complete assignment

Kibret Tecle před 6 roky
rodič
revize
115bd1fb07
15 změnil soubory, kde provedl 113 přidání a 53 odebrání
  1. 2
    0
      ChapterOneMicro.iml
  2. 54
    27
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java
  3. 17
    6
      src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java
  4. 29
    10
      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. 3
    3
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java
  7. 4
    4
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java
  8. 3
    2
      src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java
  9. binární
      target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class
  10. binární
      target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class
  11. binární
      target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class
  12. binární
      target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class
  13. binární
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class
  14. binární
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class
  15. binární
      target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class

+ 2
- 0
ChapterOneMicro.iml Zobrazit soubor

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

+ 54
- 27
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Zobrazit soubor

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

+ 17
- 6
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Zobrazit soubor

@@ -10,7 +10,9 @@ 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
+        else return false;
14 16
     }
15 17
 
16 18
     /**
@@ -19,7 +21,10 @@ 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
+        if (x<y) {
25
+            return true;
26
+        }else
27
+            return false;
23 28
     }
24 29
 
25 30
     /**
@@ -27,8 +32,11 @@ public class PredicateUtilities {
27 32
      * @param y
28 33
      * @return true if `x` is greater than or equal to `y`
29 34
      */
30
-    public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
35
+    public Boolean isGreaterThanOrEqualTo(int x, int y)
36
+    {
37
+        if(x>=y)
38
+        return true;
39
+        else return false;
32 40
     }
33 41
 
34 42
     /**
@@ -36,7 +44,10 @@ public class PredicateUtilities {
36 44
      * @param y
37 45
      * @return true if `x` is less than or equal to `y`
38 46
      */
39
-    public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
47
+    public Boolean isLessThanOrEqualTo(int x, int y)
48
+    {
49
+        if(x<=y)
50
+        return true;
51
+        else return false;
41 52
     }
42 53
 }

+ 29
- 10
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Zobrazit soubor

@@ -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,input.length());
46 51
     }
47 52
 
48 53
     /**
@@ -51,7 +56,8 @@ 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
     /**
@@ -59,7 +65,9 @@ public class StringUtilities {
59 65
      * @return the middle character of `inputValue`
60 66
      */
61 67
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
68
+        if(inputValue.length()%2!=0) {
69
+            return inputValue.charAt((inputValue.length() / 2));
70
+        }else return inputValue.charAt(inputValue.length()/2-1);
63 71
     }
64 72
 
65 73
     /**
@@ -67,7 +75,11 @@ public class StringUtilities {
67 75
      * @return the first sequence of characters
68 76
      */
69 77
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
78
+        for(int i=0;i<spaceDelimitedString.length();i++){
79
+            if(spaceDelimitedString.charAt(i)==' ') {
80
+                return spaceDelimitedString.substring(0,i);
81
+            }
82
+        }return null;
71 83
     }
72 84
 
73 85
     /**
@@ -75,7 +87,8 @@ public class StringUtilities {
75 87
      * @return the second word of a string delimited by spaces.
76 88
      */
77 89
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
90
+        String[] words= spaceDelimitedString.split(" ");
91
+        return words[1];
79 92
     }
80 93
 
81 94
     /**
@@ -83,6 +96,12 @@ public class StringUtilities {
83 96
      * @return an identical string with characters in reverse order.
84 97
      */
85 98
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
99
+        String reverseString="";
100
+
101
+        char[] myChar = stringToReverse.toCharArray();
102
+        for(int i= myChar.length-1;i>=0;i--){
103
+            reverseString+=myChar[i];
104
+        }
105
+        return reverseString;
87 106
     }
88 107
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Zobrazit soubor

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

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Zobrazit soubor

@@ -36,7 +36,7 @@ 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
@@ -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() {
@@ -295,7 +295,7 @@ public class TestMathUtilities {
295 295
     public void testMultiplication3() {
296 296
         // : Given
297 297
         byte multiplicand = 16;
298
-        byte multiplier = 14;
298
+        byte multiplier = 4;
299 299
         byte expectedByte = 64;
300 300
         // : When
301 301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);

+ 4
- 4
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Zobrazit soubor

@@ -27,7 +27,7 @@ public class TestPredicateUtilities {
27 27
     public void testGreaterThanFalse(){
28 28
         // : Given
29 29
         int greaterValue = 350;
30
-        int lesserValue = 350;
30
+        int lesserValue = 349;
31 31
 
32 32
         // : When
33 33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
@@ -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
 
@@ -109,8 +109,8 @@ public class TestPredicateUtilities {
109 109
     @Test
110 110
     public void testGreaterOrEqual2(){
111 111
         // : Given
112
-        int greaterValue = 8;
113
-        int lesserValue = 15;
112
+        int greaterValue = 15;
113
+        int lesserValue = 8;
114 114
 
115 115
         // : When
116 116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);

+ 3
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Zobrazit soubor

@@ -56,7 +56,8 @@ public class TestStringUtilities {
56 56
     public void substringBeginTest(){
57 57
         // : Given
58 58
         String input = "Hello";
59
-        String expected = "olleH";
59
+       // String expected = "olleH";
60
+        String expected = "Hel";
60 61
 
61 62
         // : When
62 63
         String actual = StringUtilities.getPrefix(input);
@@ -154,7 +155,7 @@ public class TestStringUtilities {
154 155
         String expected = "Wilmington";
155 156
 
156 157
         // : When
157
-        String actual = StringUtilities.getFirstWord(input);
158
+        String actual = StringUtilities.getSecondWord(input);
158 159
 
159 160
         // : Then
160 161
         assertEquals(expected, actual);

binární
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Zobrazit soubor


binární
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Zobrazit soubor


binární
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Zobrazit soubor


binární
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Zobrazit soubor


binární
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Zobrazit soubor


binární
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Zobrazit soubor


binární
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Zobrazit soubor