#30 DanDoBetterDrills

Открыто
NiraParikh хочет смерджить 1 коммит(ов) из NiraParikh/CR-MicroLabs-JavaFundamentals-DanDoBetterDrills:master в master
8 измененных файлов: 153 добавлений и 54 удалений
  1. Двоичные данные
      MathUtilities.class
  2. 79
    26
      MathUtilities.java
  3. Двоичные данные
      PredicateUtilities.class
  4. 21
    5
      PredicateUtilities.java
  5. 1
    1
      PredicateUtilitiesTest.java
  6. Двоичные данные
      StringUtilities.class
  7. 38
    11
      StringUtilities.java
  8. 14
    11
      package.bluej

Двоичные данные
MathUtilities.class Просмотреть файл


+ 79
- 26
MathUtilities.java Просмотреть файл

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

Двоичные данные
PredicateUtilities.class Просмотреть файл


+ 21
- 5
PredicateUtilities.java Просмотреть файл

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
@@ -10,7 +9,11 @@ public class PredicateUtilities {
10 9
      * @return true if `x` is greater than `y`
11 10
      */
12 11
     public Boolean isGreaterThan(int x, int y) {
13
-        return null;
12
+        if (x>y){
13
+            return true;
14
+        } else {
15
+            return false;
16
+        }   
14 17
     }
15 18
 
16 19
     /**
@@ -19,7 +22,11 @@ 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;
29
+        }   
23 30
     }
24 31
 
25 32
     /**
@@ -28,7 +35,11 @@ public class PredicateUtilities {
28 35
      * @return true if `x` is greater than or equal to `y`
29 36
      */
30 37
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
38
+        if (x>=y){
39
+            return true;
40
+        } else {
41
+            return false;
42
+        }   
32 43
     }
33 44
 
34 45
     /**
@@ -37,6 +48,11 @@ public class PredicateUtilities {
37 48
      * @return true if `x` is less than or equal to `y`
38 49
      */
39 50
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
51
+        if (x<=y){
52
+            return true;
53
+        } else {
54
+            return false;
55
+        }   
56
+    
41 57
     }
42 58
 }

+ 1
- 1
PredicateUtilitiesTest.java Просмотреть файл

@@ -17,7 +17,7 @@ public class PredicateUtilitiesTest {
17 17
         int lesserValue = 350;
18 18
 
19 19
 
20
-        // : When
20
+        // : When 
21 21
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
22 22
 
23 23
         // : Then

Двоичные данные
StringUtilities.class Просмотреть файл


+ 38
- 11
StringUtilities.java Просмотреть файл

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
@@ -8,7 +7,8 @@ public class StringUtilities {
8 7
      * @return `Hello World` as a string
9 8
      */
10 9
     public static String getHelloWorld() {
11
-        return null;
10
+        String abc = "Hello World";
11
+        return abc;
12 12
     }
13 13
 
14 14
     /**
@@ -17,7 +17,8 @@ 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
+        String cat = firstSegment + secondSegment;
21
+        return cat;
21 22
     }
22 23
 
23 24
     /**
@@ -26,7 +27,9 @@ public class StringUtilities {
26 27
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 28
      */
28 29
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
30
+
31
+        String con = firstSegment + secondSegment;
32
+        return con;
30 33
     }
31 34
 
32 35
     /**
@@ -34,7 +37,10 @@ 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
+        String abc = input.substring(0,3);
42
+        return abc;
43
+
38 44
     }
39 45
 
40 46
     /**
@@ -42,7 +48,8 @@ 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
+        String abc = input.substring(2,5);
52
+        return abc;
46 53
     }
47 54
 
48 55
     /**
@@ -51,7 +58,9 @@ public class StringUtilities {
51 58
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 59
      */
53 60
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
61
+        Boolean abc = inputValue.equals (comparableValue);
62
+        return abc;
63
+
55 64
     }
56 65
 
57 66
     /**
@@ -59,7 +68,17 @@ 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 val = 0;
72
+        char mid = 0;
73
+
74
+        if (inputValue.length() %2 == 0) {
75
+
76
+            mid = inputValue.charAt (inputValue.length ()/2 -1);
77
+        } else{
78
+            mid = inputValue.charAt (inputValue.length ()/2);
79
+        }
80
+
81
+        return mid;
63 82
     }
64 83
 
65 84
     /**
@@ -67,15 +86,17 @@ public class StringUtilities {
67 86
      * @return the first sequence of characters
68 87
      */
69 88
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
89
+
90
+        return spaceDelimitedString.split(" ") [0];
71 91
     }
72 92
 
73 93
     /**
74 94
      * @param spaceDelimitedString a string delimited by spaces
75 95
      * @return the second word of a string delimited by spaces.
76 96
      */
97
+
77 98
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
99
+        return spaceDelimitedString.split(" ") [1];
79 100
     }
80 101
 
81 102
     /**
@@ -83,6 +104,12 @@ public class StringUtilities {
83 104
      * @return an identical string with characters in reverse order.
84 105
      */
85 106
     public static String reverse(String stringToReverse){
86
-        return null;
107
+        String wo = "";
108
+        for (int i = stringToReverse.length()-1;i >=0; i--) {
109
+            wo += stringToReverse.charAt(i);
110
+            
111
+        }
112
+        return wo;
87 113
     }
88 114
 }
115
+

+ 14
- 11
package.bluej Просмотреть файл

@@ -1,19 +1,22 @@
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
+dependency1.from=PredicateUtilitiesTest
3
+dependency1.to=PredicateUtilities
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=709
6
+editor.fx.0.width=933
7
+editor.fx.0.x=394
8
+editor.fx.0.y=23
6 9
 objectbench.height=129
7
-objectbench.width=1171
8
-package.divider.horizontal=0.6
10
+objectbench.width=513
11
+package.divider.horizontal=0.6004618937644342
9 12
 package.divider.vertical=0.7490774907749077
10 13
 package.editor.height=399
11
-package.editor.width=1069
12
-package.editor.x=59
13
-package.editor.y=63
14
+package.editor.width=760
15
+package.editor.x=112
16
+package.editor.y=31
14 17
 package.frame.height=600
15
-package.frame.width=1195
16
-package.numDependencies=0
18
+package.frame.width=886
19
+package.numDependencies=1
17 20
 package.numTargets=6
18 21
 package.showExtends=true
19 22
 package.showUses=true