#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
      * @return sum of `baseValue` and `difference`
11
      * @return sum of `baseValue` and `difference`
12
      */
12
      */
13
     public Integer add(int baseValue, int difference) {
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
      * @return sum of `baseValue` and `difference`
22
      * @return sum of `baseValue` and `difference`
21
      */
23
      */
22
     public Long add(long baseValue, long difference) {
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
      * @return sum of `baseValue` and `difference`
34
      * @return sum of `baseValue` and `difference`
30
      */
35
      */
31
     public Short add(short baseValue, short difference) {
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
      * @return sum of `baseValue` and `difference`
47
      * @return sum of `baseValue` and `difference`
39
      */
48
      */
40
     public Byte add(byte baseValue, byte difference) {
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
      * @return sum of `baseValue` and `difference`
59
      * @return sum of `baseValue` and `difference`
48
      */
60
      */
49
     public Float add(float baseValue, float difference) {
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
      * @return sum of `baseValue` and `difference`
70
      * @return sum of `baseValue` and `difference`
57
      */
71
      */
58
     public Double add(double baseValue, double difference) {
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
      * @return difference between `baseValue` and `difference`
80
      * @return difference between `baseValue` and `difference`
66
      */
81
      */
67
     public Integer subtract(int baseValue, int difference) {
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
      * @return difference between `baseValue` and `difference`
90
      * @return difference between `baseValue` and `difference`
75
      */
91
      */
76
     public Long subtract(long baseValue, long difference) {
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
      * @return difference between `baseValue` and `difference`
100
      * @return difference between `baseValue` and `difference`
84
      */
101
      */
85
     public Short subtract(short baseValue, short difference) {
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
      * @return difference between `baseValue` and `difference`
115
      * @return difference between `baseValue` and `difference`
93
      */
116
      */
94
     public Byte subtract(byte baseValue, byte difference) {
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
      * @return difference between `baseValue` and `difference`
129
      * @return difference between `baseValue` and `difference`
102
      */
130
      */
103
     public Float subtract(float baseValue, float difference) {
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
      * @return difference between `baseValue` and `difference`
139
      * @return difference between `baseValue` and `difference`
111
      */
140
      */
112
     public Double subtract(double baseValue, double difference) {
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
      * @return division of `dividend` by `divisor
150
      * @return division of `dividend` by `divisor
121
      */
151
      */
122
     public Integer divide(int dividend, int divisor) {
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
      * @return division of `dividend` by `divisor
160
      * @return division of `dividend` by `divisor
130
      */
161
      */
131
     public Long divide(long dividend, long divisor) {
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
      * @return division of `dividend` by `divisor
170
      * @return division of `dividend` by `divisor
139
      */
171
      */
140
     public Short divide(short dividend, short divisor) {
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
      * @return division of `dividend` by `divisor
182
      * @return division of `dividend` by `divisor
148
      */
183
      */
149
     public Byte divide(byte dividend, byte divisor) {
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
      * @return division of `dividend` by `divisor
194
      * @return division of `dividend` by `divisor
157
      */
195
      */
158
     public Float divide(float dividend, float divisor) {
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
      * @return division of `dividend` by `divisor
204
      * @return division of `dividend` by `divisor
166
      */
205
      */
167
     public Double divide(double dividend, double divisor) {
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
      * @return product of `multiplicand` by `multiplier`
215
      * @return product of `multiplicand` by `multiplier`
176
      */
216
      */
177
     public Integer multiply(int multiplicand, int multiplier) {
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
      * @return product of `multiplicand` by `multiplier`
226
      * @return product of `multiplicand` by `multiplier`
185
      */
227
      */
186
     public Long multiply(long multiplicand, long multiplier) {
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
      * @return product of `multiplicand` by `multiplier`
236
      * @return product of `multiplicand` by `multiplier`
194
      */
237
      */
195
     public Short multiply(short multiplicand, short multiplier) {
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
      * @param multiplicand value to be multiplied
245
      * @param multiplicand value to be multiplied
201
      * @return product of `multiplicand` by `multiplier`
247
      * @return product of `multiplicand` by `multiplier`
202
      */
248
      */
203
     public Byte multiply(byte multiplicand, byte multiplier) {
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
      * @return product of `multiplicand` by `multiplier`
259
      * @return product of `multiplicand` by `multiplier`
211
      */
260
      */
212
     public Float multiply(float multiplicand, float multiplier) {
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
      * @return product of `multiplicand` by `multiplier`
269
      * @return product of `multiplicand` by `multiplier`
220
      */
270
      */
221
     public Double multiply(double multiplicand, double multiplier) {
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
       * @return true
278
       * @return true
228
      */
279
      */
229
     public Boolean returnTrue() {
280
     public Boolean returnTrue() {
230
-        return null;
281
+       
282
+       
283
+        return true ;
231
     }
284
     }
232
 
285
 
233
     /**
286
     /**
234
      * @return false
287
      * @return false
235
      */
288
      */
236
     public Boolean returnFalse() {
289
     public Boolean returnFalse() {
237
-        return null;
290
+        return false;
238
     }
291
     }
239
 
292
 
240
 }
293
 }

二进制
PredicateUtilities.class 查看文件


+ 21
- 5
PredicateUtilities.java 查看文件

1
- 
2
 
1
 
3
 /**
2
 /**
4
  * Created by dan on 6/14/17.
3
  * Created by dan on 6/14/17.
10
      * @return true if `x` is greater than `y`
9
      * @return true if `x` is greater than `y`
11
      */
10
      */
12
     public Boolean isGreaterThan(int x, int y) {
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
      * @return true if `x` is less than `y`
22
      * @return true if `x` is less than `y`
20
      */
23
      */
21
     public Boolean isLessThan(int x, int y) {
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
      * @return true if `x` is greater than or equal to `y`
35
      * @return true if `x` is greater than or equal to `y`
29
      */
36
      */
30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
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
      * @return true if `x` is less than or equal to `y`
48
      * @return true if `x` is less than or equal to `y`
38
      */
49
      */
39
     public Boolean isLessThanOrEqualTo(int x, int y) {
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
         int lesserValue = 350;
17
         int lesserValue = 350;
18
 
18
 
19
 
19
 
20
-        // : When
20
+        // : When 
21
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
21
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
22
 
22
 
23
         // : Then
23
         // : Then

二进制
StringUtilities.class 查看文件


+ 38
- 11
StringUtilities.java 查看文件

1
- 
2
 
1
 
3
 /**
2
 /**
4
  * Created by dan on 6/14/17.
3
  * Created by dan on 6/14/17.
8
      * @return `Hello World` as a string
7
      * @return `Hello World` as a string
9
      */
8
      */
10
     public static String getHelloWorld() {
9
     public static String getHelloWorld() {
11
-        return null;
10
+        String abc = "Hello World";
11
+        return abc;
12
     }
12
     }
13
 
13
 
14
     /**
14
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
18
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
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
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
28
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
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
      * @return the first 3 characters of `input`
37
      * @return the first 3 characters of `input`
35
      */
38
      */
36
     public static String getPrefix(String input){
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
      * @return the last 3 characters of `input`
48
      * @return the last 3 characters of `input`
43
      */
49
      */
44
     public static String getSuffix(String input){
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
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
58
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
59
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
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
      * @return the middle character of `inputValue`
68
      * @return the middle character of `inputValue`
60
      */
69
      */
61
     public static Character getMiddleCharacter(String inputValue){
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
      * @return the first sequence of characters
86
      * @return the first sequence of characters
68
      */
87
      */
69
     public static String getFirstWord(String spaceDelimitedString){
88
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
89
+
90
+        return spaceDelimitedString.split(" ") [0];
71
     }
91
     }
72
 
92
 
73
     /**
93
     /**
74
      * @param spaceDelimitedString a string delimited by spaces
94
      * @param spaceDelimitedString a string delimited by spaces
75
      * @return the second word of a string delimited by spaces.
95
      * @return the second word of a string delimited by spaces.
76
      */
96
      */
97
+
77
     public static String getSecondWord(String spaceDelimitedString){
98
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
99
+        return spaceDelimitedString.split(" ") [1];
79
     }
100
     }
80
 
101
 
81
     /**
102
     /**
83
      * @return an identical string with characters in reverse order.
104
      * @return an identical string with characters in reverse order.
84
      */
105
      */
85
     public static String reverse(String stringToReverse){
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
 #BlueJ package file
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
 objectbench.height=129
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
 package.divider.vertical=0.7490774907749077
12
 package.divider.vertical=0.7490774907749077
10
 package.editor.height=399
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
 package.frame.height=600
17
 package.frame.height=600
15
-package.frame.width=1195
16
-package.numDependencies=0
18
+package.frame.width=886
19
+package.numDependencies=1
17
 package.numTargets=6
20
 package.numTargets=6
18
 package.showExtends=true
21
 package.showExtends=true
19
 package.showUses=true
22
 package.showUses=true