#38 DDBD

Atvērta
jasamuels vēlas sapludināt 1 revīzijas no jasamuels/CR-MicroLabs-JavaFundamentals-DanDoBetterDrills:master uz master
7 mainītis faili ar 112 papildinājumiem un 48 dzēšanām
  1. Binārs
      MathUtilities.class
  2. 59
    26
      MathUtilities.java
  3. Binārs
      PredicateUtilities.class
  4. 16
    4
      PredicateUtilities.java
  5. Binārs
      StringUtilities.class
  6. 30
    11
      StringUtilities.java
  7. 7
    7
      package.bluej

Binārs
MathUtilities.class Parādīt failu


+ 59
- 26
MathUtilities.java Parādīt failu

@@ -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 solution = baseValue + difference;
15
+        return solution;
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 solution = baseValue + difference;
25
+        return solution;
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 solution = (short) (baseValue + difference);
35
+        return solution;
33 36
     }
34 37
 
35 38
     /**
@@ -38,7 +41,9 @@ 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
+        int first = baseValue + difference;
45
+        byte solution = (byte)first;
46
+        return solution;
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 solution = baseValue + difference;
56
+        return solution;
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
+        double solution = baseValue + difference;
66
+        return solution;
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
+        int solution = baseValue - difference;
76
+        return solution;
69 77
     }
70 78
 
71 79
     /**
@@ -74,7 +82,8 @@ public class MathUtilities {
74 82
      * @return difference between `baseValue` and `difference`
75 83
      */
76 84
     public Long subtract(long baseValue, long difference) {
77
-        return null;
85
+        long solution = baseValue - difference;
86
+        return solution;
78 87
     }
79 88
 
80 89
     /**
@@ -83,7 +92,9 @@ 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
+        int convert = (short) baseValue - difference;
96
+        short solution = (short) convert;
97
+        return solution;
87 98
     }
88 99
 
89 100
     /**
@@ -92,7 +103,9 @@ public class MathUtilities {
92 103
      * @return difference between `baseValue` and `difference`
93 104
      */
94 105
     public Byte subtract(byte baseValue, byte difference) {
95
-        return null;
106
+        int conversion = baseValue - difference;
107
+        byte solution = (byte) conversion;
108
+        return solution;
96 109
     }
97 110
 
98 111
     /**
@@ -101,7 +114,8 @@ public class MathUtilities {
101 114
      * @return difference between `baseValue` and `difference`
102 115
      */
103 116
     public Float subtract(float baseValue, float difference) {
104
-        return null;
117
+        float solution = baseValue - difference;
118
+        return solution;
105 119
     }
106 120
 
107 121
     /**
@@ -110,7 +124,8 @@ public class MathUtilities {
110 124
      * @return difference between `baseValue` and `difference`
111 125
      */
112 126
     public Double subtract(double baseValue, double difference) {
113
-        return null;
127
+        double solution = baseValue - difference;
128
+        return solution;
114 129
     }
115 130
 
116 131
 
@@ -120,7 +135,8 @@ public class MathUtilities {
120 135
      * @return division of `dividend` by `divisor
121 136
      */
122 137
     public Integer divide(int dividend, int divisor) {
123
-        return null;
138
+        int division = dividend / divisor;
139
+        return division;
124 140
     }
125 141
 
126 142
     /**
@@ -129,7 +145,8 @@ public class MathUtilities {
129 145
      * @return division of `dividend` by `divisor
130 146
      */
131 147
     public Long divide(long dividend, long divisor) {
132
-        return null;
148
+        long division = dividend / divisor;
149
+        return division;
133 150
     }
134 151
 
135 152
     /**
@@ -138,7 +155,9 @@ public class MathUtilities {
138 155
      * @return division of `dividend` by `divisor
139 156
      */
140 157
     public Short divide(short dividend, short divisor) {
141
-        return null;
158
+        int convert = dividend / divisor;
159
+        short solution = (short) convert;
160
+        return solution;
142 161
     }
143 162
 
144 163
     /**
@@ -147,7 +166,9 @@ public class MathUtilities {
147 166
      * @return division of `dividend` by `divisor
148 167
      */
149 168
     public Byte divide(byte dividend, byte divisor) {
150
-        return null;
169
+        int convert = dividend / divisor;
170
+        byte solution = (byte) convert;
171
+        return solution;
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 solution = dividend / divisor;
181
+        return solution;
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 solution = dividend / divisor;
191
+        return solution;
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 solution = multiplicand * multiplier;
202
+        return solution;
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 solution = multiplicand * multiplier;
212
+        return solution;
188 213
     }
189 214
 
190 215
     /**
@@ -193,7 +218,9 @@ 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
+        int convert = multiplicand * multiplier;
222
+        short solution = (short) convert;
223
+        return solution;
197 224
     }
198 225
     /**
199 226
      * @param multiplicand value to be multiplied
@@ -201,7 +228,9 @@ public class MathUtilities {
201 228
      * @return product of `multiplicand` by `multiplier`
202 229
      */
203 230
     public Byte multiply(byte multiplicand, byte multiplier) {
204
-        return null;
231
+        int convert = multiplicand * multiplier;
232
+        byte solution = (byte) convert;
233
+        return solution;
205 234
     }
206 235
 
207 236
     /**
@@ -210,7 +239,8 @@ public class MathUtilities {
210 239
      * @return product of `multiplicand` by `multiplier`
211 240
      */
212 241
     public Float multiply(float multiplicand, float multiplier) {
213
-        return null;
242
+        float solution = multiplicand * multiplier;
243
+        return solution;
214 244
     }
215 245
 
216 246
     /**
@@ -219,7 +249,8 @@ public class MathUtilities {
219 249
      * @return product of `multiplicand` by `multiplier`
220 250
      */
221 251
     public Double multiply(double multiplicand, double multiplier) {
222
-        return null;
252
+        double solution = multiplicand * multiplier;
253
+        return solution;
223 254
     }
224 255
 
225 256
 
@@ -227,14 +258,16 @@ public class MathUtilities {
227 258
       * @return true
228 259
      */
229 260
     public Boolean returnTrue() {
230
-        return null;
261
+        boolean solution = true;
262
+        return solution;
231 263
     }
232 264
 
233 265
     /**
234 266
      * @return false
235 267
      */
236 268
     public Boolean returnFalse() {
237
-        return null;
269
+        boolean solution = false;
270
+        return solution;
238 271
     }
239 272
 
240 273
 }

Binārs
PredicateUtilities.class Parādīt failu


+ 16
- 4
PredicateUtilities.java Parādīt failu

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

Binārs
StringUtilities.class Parādīt failu


+ 30
- 11
StringUtilities.java Parādīt failu

@@ -1,4 +1,6 @@
1
- 
1
+import java.lang.*; 
2
+import java.io.*; 
3
+import java.util.*;
2 4
 
3 5
 /**
4 6
  * Created by dan on 6/14/17.
@@ -8,7 +10,8 @@ public class StringUtilities {
8 10
      * @return `Hello World` as a string
9 11
      */
10 12
     public static String getHelloWorld() {
11
-        return null;
13
+        String solution = "Hello World";
14
+        return solution;
12 15
     }
13 16
 
14 17
     /**
@@ -17,7 +20,8 @@ public class StringUtilities {
17 20
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 21
      */
19 22
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
23
+        String solution = firstSegment + secondSegment;
24
+        return solution;
21 25
     }
22 26
 
23 27
     /**
@@ -26,7 +30,9 @@ public class StringUtilities {
26 30
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 31
      */
28 32
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
33
+        String convert = Integer.toString(firstSegment);
34
+        String solution = convert + secondSegment;
35
+        return solution;
30 36
     }
31 37
 
32 38
     /**
@@ -34,7 +40,7 @@ public class StringUtilities {
34 40
      * @return the first 3 characters of `input`
35 41
      */
36 42
     public static String getPrefix(String input){
37
-        return null;
43
+        return input.substring(0,3);
38 44
     }
39 45
 
40 46
     /**
@@ -42,7 +48,7 @@ public class StringUtilities {
42 48
      * @return the last 3 characters of `input`
43 49
      */
44 50
     public static String getSuffix(String input){
45
-        return null;
51
+        return input.substring(input.length() - 3);
46 52
     }
47 53
 
48 54
     /**
@@ -51,7 +57,10 @@ public class StringUtilities {
51 57
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 58
      */
53 59
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
60
+        if (inputValue == comparableValue) {
61
+            return true;} else {
62
+                return false;}
63
+                
55 64
     }
56 65
 
57 66
     /**
@@ -59,7 +68,13 @@ public class StringUtilities {
59 68
      * @return the middle character of `inputValue`
60 69
      */
61 70
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
71
+        int length = inputValue.length() - 1; // 6
72
+        int middle = length / 2; //3
73
+        String math = String.valueOf(middle + 1); //4
74
+        int halfway = Integer.valueOf(math); //4
75
+        String thechar = inputValue.substring(halfway - 1, halfway);
76
+        char itsthechar = thechar.charAt(0);
77
+        return itsthechar;
63 78
     }
64 79
 
65 80
     /**
@@ -67,7 +82,8 @@ public class StringUtilities {
67 82
      * @return the first sequence of characters
68 83
      */
69 84
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
85
+        String[] splitem = spaceDelimitedString.split("\\s+");
86
+        return splitem[0];
71 87
     }
72 88
 
73 89
     /**
@@ -75,7 +91,8 @@ public class StringUtilities {
75 91
      * @return the second word of a string delimited by spaces.
76 92
      */
77 93
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
94
+        String[] splitem = spaceDelimitedString.split("\\s+");
95
+        return splitem[1];
79 96
     }
80 97
 
81 98
     /**
@@ -83,6 +100,8 @@ public class StringUtilities {
83 100
      * @return an identical string with characters in reverse order.
84 101
      */
85 102
     public static String reverse(String stringToReverse){
86
-        return null;
103
+        StringBuilder easy = new StringBuilder();
104
+        easy.append(stringToReverse);
105
+        return easy.reverse().toString();
87 106
     }
88 107
 }

+ 7
- 7
package.bluej Parādīt failu

@@ -1,13 +1,13 @@
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
6
-objectbench.height=129
2
+editor.fx.0.height=709
3
+editor.fx.0.width=1001
4
+editor.fx.0.x=296
5
+editor.fx.0.y=23
6
+objectbench.height=128
7 7
 objectbench.width=1171
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.7490774907749077
10
-package.editor.height=399
9
+package.divider.vertical=0.7509225092250923
10
+package.editor.height=400
11 11
 package.editor.width=1069
12 12
 package.editor.x=59
13 13
 package.editor.y=63