#42 Jason Gibbs, Jase256

開啟中
JaseG256 請求將 1 次程式碼提交從 JaseG256/ZCW-Lab-Fundamental-Methods:master 合併至 master
共有 8 個文件被更改,包括 68 次插入43 次删除
  1. 28
    26
      MathUtilities.java
  2. 0
    0
      MathUtilitiesTest.java
  3. 20
    4
      PredicateUtilities.java
  4. 0
    0
      PredicateUtilitiesTest.java
  5. 0
    0
      README.md
  6. 20
    13
      StringUtilities.java
  7. 0
    0
      StringUtilitiesTest.java
  8. 0
    0
      package.bluej

+ 28
- 26
MathUtilities.java 查看文件

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

+ 0
- 0
MathUtilitiesTest.java 查看文件


+ 20
- 4
PredicateUtilities.java 查看文件

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

+ 0
- 0
PredicateUtilitiesTest.java 查看文件


+ 0
- 0
README.md 查看文件


+ 20
- 13
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,9 @@ 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
+     
39
+  
38 40
     }
39 41
 
40 42
     /**
@@ -42,7 +44,7 @@ public class StringUtilities {
42 44
      * @return the last 3 characters of `input`
43 45
      */
44 46
     public String getSuffix(String input){
45
-        return null;
47
+        return input.substring(input.length()-3);
46 48
     }
47 49
 
48 50
     /**
@@ -51,7 +53,11 @@ public class StringUtilities {
51 53
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 54
      */
53 55
     public Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
56
+        if (inputValue.equals(comparableValue)){    
57
+        return true;
58
+        } else {
59
+            return false;
60
+        }
55 61
     }
56 62
 
57 63
     /**
@@ -59,15 +65,15 @@ public class StringUtilities {
59 65
      * @return the middle character of `inputValue`
60 66
      */
61 67
     public Character getMiddleCharacter(String inputValue){
62
-        return null;
63
-    }
68
+        return inputValue.charAt((inputValue.length() - 1) / 2);
69
+}
64 70
 
65 71
     /**
66 72
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 73
      * @return the first sequence of characters
68 74
      */
69 75
     public String getFirstWord(String spaceDelimitedString){
70
-        return null;
76
+        return spaceDelimitedString.split(" ")[0];
71 77
     }
72 78
 
73 79
     /**
@@ -75,7 +81,7 @@ public class StringUtilities {
75 81
      * @return the second word of a string delimited by spaces.
76 82
      */
77 83
     public String getSecondWord(String spaceDelimitedString){
78
-        return null;
84
+        return spaceDelimitedString.split(" ")[1];
79 85
     }
80 86
 
81 87
     /**
@@ -83,7 +89,8 @@ public class StringUtilities {
83 89
      * @return an identical string with characters in reverse order.
84 90
      */
85 91
     public String reverse(String stringToReverse){
86
-        return null;
92
+        StringBuilder builder = new StringBuilder(stringToReverse);
93
+        return builder.reverse().toString();
87 94
     }
88 95
 
89 96
     /**
@@ -91,7 +98,7 @@ public class StringUtilities {
91 98
      * @return an identical string with spaces removed.
92 99
      */
93 100
     public String removeWhitespace(String input){
94
-        return null;
101
+        return input.replaceAll("\\s+", "");
95 102
     }
96 103
 
97 104
     /**
@@ -99,6 +106,6 @@ public class StringUtilities {
99 106
      * @return an identical string with spaces in the front and end removed.
100 107
      */
101 108
     public String trim(String input){
102
-        return null;
109
+        return input.trim();
103 110
     }
104 111
 }

+ 0
- 0
StringUtilitiesTest.java 查看文件


+ 0
- 0
package.bluej 查看文件