Aliza Lang 6 年前
父节点
当前提交
f4b44fd84f
共有 4 个文件被更改,包括 105 次插入66 次删除
  1. 51
    26
      MathUtilities.java
  2. 18
    7
      PredicateUtilities.java
  3. 17
    14
      StringUtilities.java
  4. 19
    19
      package.bluej

+ 51
- 26
MathUtilities.java 查看文件

@@ -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 add = (short) (baseValue + difference);
35
+       return add;
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 add = (byte) (baseValue + difference);
45
+       return add;
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 add = baseValue + difference;
55
+       return add;
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 add = baseValue + difference;
65
+       return add;
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 subtract = baseValue - difference;
75
+       return subtract;
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 subtract = baseValue - difference;
85
+       return subtract;
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 subtract = (short) (baseValue - difference);
95
+       return subtract;
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 subtract = (byte) (baseValue - difference);
105
+       return subtract;
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 subtract = baseValue - difference;
115
+       return subtract;
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 subtract = baseValue - difference;
125
+       return subtract;
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 divide = dividend / divisor;
136
+       return divide;
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 divide = dividend / divisor;
146
+       return divide;
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 divide = (short) (dividend / divisor);
156
+       return divide;
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 divide = (byte) (dividend / divisor);
166
+       return divide;
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 divide = dividend / divisor;
176
+       return divide;
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 divide = dividend / divisor;
186
+       return divide;
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 multiply = multiplicand * multiplier;
197
+       return multiply;
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 multiply = multiplicand * multiplier;
207
+       return multiply;
188 208
    }
189 209
 
190 210
    /**
@@ -193,7 +213,9 @@ 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 multiply = (short) (multiplicand * multiplier);
217
+       return multiply;
218
+
197 219
    }
198 220
    /**
199 221
     * @param multiplicand value to be multiplied
@@ -201,7 +223,8 @@ public class MathUtilities {
201 223
     * @return product of `multiplicand` by `multiplier`
202 224
     */
203 225
    public Byte multiply(byte multiplicand, byte multiplier) {
204
-       return null;
226
+       byte multiply = (byte) (multiplicand * multiplier);
227
+       return multiply;
205 228
    }
206 229
 
207 230
    /**
@@ -210,7 +233,8 @@ public class MathUtilities {
210 233
     * @return product of `multiplicand` by `multiplier`
211 234
     */
212 235
    public Float multiply(float multiplicand, float multiplier) {
213
-       return null;
236
+       float multiply = multiplicand * multiplier;
237
+       return multiply;
214 238
    }
215 239
 
216 240
    /**
@@ -219,7 +243,8 @@ public class MathUtilities {
219 243
     * @return product of `multiplicand` by `multiplier`
220 244
     */
221 245
    public Double multiply(double multiplicand, double multiplier) {
222
-       return null;
246
+       double multiply = multiplicand * multiplier;
247
+       return multiply;
223 248
    }
224 249
 
225 250
 
@@ -227,14 +252,14 @@ public class MathUtilities {
227 252
      * @return true
228 253
     */
229 254
    public Boolean returnTrue() {
230
-       return null;
255
+       return true;
231 256
    }
232 257
 
233 258
    /**
234 259
     * @return false
235 260
     */
236 261
    public Boolean returnFalse() {
237
-       return null;
262
+       return false;
238 263
    }
239 264
 
240 265
 }

+ 18
- 7
PredicateUtilities.java 查看文件

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

+ 17
- 14
StringUtilities.java 查看文件

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

+ 19
- 19
package.bluej 查看文件

@@ -1,27 +1,27 @@
1 1
 #BlueJ package file
2
-dependency1.from=StringUtilitiesTest
3
-dependency1.to=StringUtilities
2
+dependency1.from=PredicateUtilitiesTest
3
+dependency1.to=PredicateUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=PredicateUtilitiesTest
6
-dependency2.to=PredicateUtilities
5
+dependency2.from=MathUtilitiesTest
6
+dependency2.to=MathUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=MathUtilitiesTest
9
-dependency3.to=MathUtilities
8
+dependency3.from=StringUtilitiesTest
9
+dependency3.to=StringUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=0
12
-editor.fx.0.width=0
13
-editor.fx.0.x=0
14
-editor.fx.0.y=0
11
+editor.fx.0.height=722
12
+editor.fx.0.width=800
13
+editor.fx.0.x=320
14
+editor.fx.0.y=51
15 15
 objectbench.height=145
16
-objectbench.width=776
17
-package.divider.horizontal=0.6
18
-package.divider.vertical=0.7195571955719557
19
-package.editor.height=383
20
-package.editor.width=674
21
-package.editor.x=29
22
-package.editor.y=132
23
-package.frame.height=600
24
-package.frame.width=800
16
+objectbench.width=334
17
+package.divider.horizontal=0.6003521126760564
18
+package.divider.vertical=0.7591125198098256
19
+package.editor.height=456
20
+package.editor.width=462
21
+package.editor.x=403
22
+package.editor.y=23
23
+package.frame.height=689
24
+package.frame.width=588
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true