#44 jpsp91 (Jae Park)

Отворено
jpsp91 жели да споји 3 комит(е) из jpsp91/ZCW-Lab-Fundamental-Methods:master у master
4 измењених фајлова са 298 додато и 252 уклоњено
  1. 277
    233
      MathUtilities.java
  2. 4
    4
      PredicateUtilities.java
  3. 14
    12
      StringUtilities.java
  4. 3
    3
      package.bluej

+ 277
- 233
MathUtilities.java Прегледај датотеку

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

+ 4
- 4
PredicateUtilities.java Прегледај датотеку

@@ -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
 }

+ 14
- 12
StringUtilities.java Прегледај датотеку

@@ -8,7 +8,7 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public 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 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 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 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 String getSuffix(String input){
45
-        return null;
45
+        return input.substring(2);
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 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 Character getMiddleCharacter(String inputValue){
62
-        return null;
62
+        return inputValue.charAt(3);
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 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 String getSecondWord(String spaceDelimitedString){
78
-        return null;
78
+        return spaceDelimitedString.split(" ")[1];
79 79
     }
80 80
 
81 81
     /**
@@ -83,7 +83,9 @@ public class StringUtilities {
83 83
      * @return an identical string with characters in reverse order.
84 84
      */
85 85
     public String reverse(String stringToReverse){
86
-        return null;
86
+        StringBuilder sb = new StringBuilder(stringToReverse);
87
+        stringToReverse = sb.reverse().toString();
88
+        return stringToReverse;
87 89
     }
88 90
 
89 91
     /**
@@ -91,7 +93,7 @@ public class StringUtilities {
91 93
      * @return an identical string with spaces removed.
92 94
      */
93 95
     public String removeWhitespace(String input){
94
-        return null;
96
+        return input.replaceAll(" ", "");
95 97
     }
96 98
 
97 99
     /**
@@ -99,6 +101,6 @@ public class StringUtilities {
99 101
      * @return an identical string with spaces in the front and end removed.
100 102
      */
101 103
     public String trim(String input){
102
-        return null;
104
+        return input.trim();
103 105
     }
104 106
 }

+ 3
- 3
package.bluej Прегледај датотеку

@@ -13,13 +13,13 @@ editor.fx.0.width=0
13 13
 editor.fx.0.x=0
14 14
 editor.fx.0.y=0
15 15
 objectbench.height=145
16
-objectbench.width=776
16
+objectbench.width=461
17 17
 package.divider.horizontal=0.6
18 18
 package.divider.vertical=0.7195571955719557
19 19
 package.editor.height=383
20 20
 package.editor.width=674
21
-package.editor.x=29
22
-package.editor.y=132
21
+package.editor.x=219
22
+package.editor.y=88
23 23
 package.frame.height=600
24 24
 package.frame.width=800
25 25
 package.numDependencies=3