Parcourir la source

Dan do better drills

Kate Moore il y a 6 ans
Parent
révision
393d24bb65
7 fichiers modifiés avec 104 ajouts et 46 suppressions
  1. BIN
      MathUtilities.class
  2. 52
    26
      MathUtilities.java
  3. BIN
      PredicateUtilities.class
  4. 20
    4
      PredicateUtilities.java
  5. BIN
      StringUtilities.class
  6. 26
    10
      StringUtilities.java
  7. 6
    6
      package.bluej

BIN
MathUtilities.class Voir le fichier


+ 52
- 26
MathUtilities.java Voir le fichier

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

BIN
PredicateUtilities.class Voir le fichier


+ 20
- 4
PredicateUtilities.java Voir le fichier

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

BIN
StringUtilities.class Voir le fichier


+ 26
- 10
StringUtilities.java Voir le fichier

@@ -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
+        String word = "Hello World";
12
+        return word;
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
+        String result = firstSegment + secondSegment;
22
+        return result;
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
+        String word = firstSegment + secondSegment;
32
+        return word;
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,7 @@ 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
+        return input.substring(2);
46 50
     }
47 51
 
48 52
     /**
@@ -51,7 +55,8 @@ public class StringUtilities {
51 55
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 56
      */
53 57
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
58
+        boolean check = inputValue.equals(comparableValue);
59
+        return check;
55 60
     }
56 61
 
57 62
     /**
@@ -59,7 +64,12 @@ public class StringUtilities {
59 64
      * @return the middle character of `inputValue`
60 65
      */
61 66
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
67
+        if (inputValue.length() % 2 == 0){
68
+            return inputValue.charAt(inputValue.length() / 2 -1);
69
+        } else {
70
+            return inputValue.charAt(inputValue.length() / 2);
71
+        }
72
+        
63 73
     }
64 74
 
65 75
     /**
@@ -67,7 +77,9 @@ public class StringUtilities {
67 77
      * @return the first sequence of characters
68 78
      */
69 79
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
80
+        
81
+        
82
+        return spaceDelimitedString.split(" ")[0];
71 83
     }
72 84
 
73 85
     /**
@@ -75,7 +87,7 @@ 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
+        return spaceDelimitedString.split(" ")[1];
79 91
     }
80 92
 
81 93
     /**
@@ -83,6 +95,10 @@ public class StringUtilities {
83 95
      * @return an identical string with characters in reverse order.
84 96
      */
85 97
     public static String reverse(String stringToReverse){
86
-        return null;
98
+        String reverse = "";
99
+        for(int i = stringToReverse.length()-1; i >=0; i--) {
100
+            reverse += stringToReverse.charAt(i);
101
+        }
102
+        return reverse;
87 103
     }
88 104
 }

+ 6
- 6
package.bluej Voir le fichier

@@ -4,15 +4,15 @@ editor.fx.0.width=0
4 4
 editor.fx.0.x=0
5 5
 editor.fx.0.y=0
6 6
 objectbench.height=129
7
-objectbench.width=1171
7
+objectbench.width=450
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.7490774907749077
10
-package.editor.height=399
11
-package.editor.width=1069
12
-package.editor.x=59
13
-package.editor.y=63
10
+package.editor.height=383
11
+package.editor.width=348
12
+package.editor.x=1
13
+package.editor.y=23
14 14
 package.frame.height=600
15
-package.frame.width=1195
15
+package.frame.width=474
16 16
 package.numDependencies=0
17 17
 package.numTargets=6
18 18
 package.showExtends=true