#37 Do better Dan

Aperto
akeemcherry vorrebbe unire 1 commit da akeemcherry/CR-MicroLabs-JavaFundamentals-DanDoBetterDrills:master a master
7 ha cambiato i file con 64 aggiunte e 54 eliminazioni
  1. BIN
      MathUtilities.class
  2. 35
    26
      MathUtilities.java
  3. BIN
      PredicateUtilities.class
  4. 4
    4
      PredicateUtilities.java
  5. BIN
      StringUtilities.class
  6. 11
    10
      StringUtilities.java
  7. 14
    14
      package.bluej

BIN
MathUtilities.class Vedi File


+ 35
- 26
MathUtilities.java Vedi File

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

BIN
PredicateUtilities.class Vedi File


+ 4
- 4
PredicateUtilities.java Vedi File

@@ -10,7 +10,7 @@ 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
+        return x > y;
14 14
     }
15 15
 
16 16
     /**
@@ -19,7 +19,7 @@ public class PredicateUtilities {
19 19
      * @return true if `x` is less than `y`
20 20
      */
21 21
     public Boolean isLessThan(int x, int y) {
22
-        return null;
22
+        return x < y;
23 23
     }
24 24
 
25 25
     /**
@@ -28,7 +28,7 @@ public class PredicateUtilities {
28 28
      * @return true if `x` is greater than or equal to `y`
29 29
      */
30 30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
31
+        return x >= y;
32 32
     }
33 33
 
34 34
     /**
@@ -37,6 +37,6 @@ public class PredicateUtilities {
37 37
      * @return true if `x` is less than or equal to `y`
38 38
      */
39 39
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
40
+        return x <= y;
41 41
     }
42 42
 }

BIN
StringUtilities.class Vedi File


+ 11
- 10
StringUtilities.java Vedi File

@@ -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,7 @@ 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
+        return firstSegment + secondSegment;
21 21
     }
22 22
 
23 23
     /**
@@ -26,7 +26,7 @@ public class StringUtilities {
26 26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 27
      */
28 28
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
29
+        return firstSegment + secondSegment;
30 30
     }
31 31
 
32 32
     /**
@@ -34,7 +34,7 @@ public class StringUtilities {
34 34
      * @return the first 3 characters of `input`
35 35
      */
36 36
     public static String getPrefix(String input){
37
-        return null;
37
+        return input.substring(0,3);
38 38
     }
39 39
 
40 40
     /**
@@ -42,7 +42,7 @@ public class StringUtilities {
42 42
      * @return the last 3 characters of `input`
43 43
      */
44 44
     public static String getSuffix(String input){
45
-        return null;
45
+        return input.substring(2,5);
46 46
     }
47 47
 
48 48
     /**
@@ -51,7 +51,7 @@ public class StringUtilities {
51 51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 52
      */
53 53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
54
+        return inputValue.equals(comparableValue);
55 55
     }
56 56
 
57 57
     /**
@@ -59,7 +59,7 @@ public class StringUtilities {
59 59
      * @return the middle character of `inputValue`
60 60
      */
61 61
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
62
+        return inputValue.charAt((inputValue.length()-1)/2);
63 63
     }
64 64
 
65 65
     /**
@@ -67,7 +67,7 @@ public class StringUtilities {
67 67
      * @return the first sequence of characters
68 68
      */
69 69
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
70
+        return (spaceDelimitedString + " ").split(" ")[0];
71 71
     }
72 72
 
73 73
     /**
@@ -75,7 +75,7 @@ public class StringUtilities {
75 75
      * @return the second word of a string delimited by spaces.
76 76
      */
77 77
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
78
+        return (spaceDelimitedString + " ").split(" ")[1];
79 79
     }
80 80
 
81 81
     /**
@@ -83,6 +83,7 @@ public class StringUtilities {
83 83
      * @return an identical string with characters in reverse order.
84 84
      */
85 85
     public static String reverse(String stringToReverse){
86
-        return null;
86
+        String rev = new StringBuilder(stringToReverse).reverse().toString();
87
+        return rev;
87 88
     }
88 89
 }

+ 14
- 14
package.bluej Vedi File

@@ -1,8 +1,8 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=0
3
-editor.fx.0.width=0
4
-editor.fx.0.x=0
5
-editor.fx.0.y=0
2
+editor.fx.0.height=714
3
+editor.fx.0.width=800
4
+editor.fx.0.x=447
5
+editor.fx.0.y=25
6 6
 objectbench.height=129
7 7
 objectbench.width=1171
8 8
 package.divider.horizontal=0.6
@@ -45,19 +45,19 @@ target3.width=100
45 45
 target3.x=60
46 46
 target3.y=150
47 47
 target4.height=50
48
-target4.name=StringUtilities
48
+target4.name=PredicateUtilitiesTest
49 49
 target4.showInterface=false
50
-target4.type=ClassTarget
51
-target4.width=110
52
-target4.x=500
53
-target4.y=130
50
+target4.type=UnitTestTargetJunit4
51
+target4.width=160
52
+target4.x=260
53
+target4.y=50
54 54
 target5.height=50
55
-target5.name=PredicateUtilitiesTest
55
+target5.name=StringUtilities
56 56
 target5.showInterface=false
57
-target5.type=UnitTestTargetJunit4
58
-target5.width=160
59
-target5.x=260
60
-target5.y=50
57
+target5.type=ClassTarget
58
+target5.width=110
59
+target5.x=500
60
+target5.y=130
61 61
 target6.height=50
62 62
 target6.name=MathUtilitiesTest
63 63
 target6.showInterface=false