#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
     * @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
+       return baseValue + difference;
15
    }
15
    }
16
 
16
 
17
    /**
17
    /**
20
     * @return sum of `baseValue` and `difference`
20
     * @return sum of `baseValue` and `difference`
21
     */
21
     */
22
    public Long add(long baseValue, long difference) {
22
    public Long add(long baseValue, long difference) {
23
-       return null;
23
+       return baseValue + difference;
24
    }
24
    }
25
 
25
 
26
    /**
26
    /**
29
     * @return sum of `baseValue` and `difference`
29
     * @return sum of `baseValue` and `difference`
30
     */
30
     */
31
    public Short add(short baseValue, short difference) {
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
     * @return sum of `baseValue` and `difference`
39
     * @return sum of `baseValue` and `difference`
39
     */
40
     */
40
    public Byte add(byte baseValue, byte difference) {
41
    public Byte add(byte baseValue, byte difference) {
41
-       return null;
42
+       return (byte) (baseValue + difference);
43
+      
42
    }
44
    }
43
 
45
 
44
    /**
46
    /**
47
     * @return sum of `baseValue` and `difference`
49
     * @return sum of `baseValue` and `difference`
48
     */
50
     */
49
    public Float add(float baseValue, float difference) {
51
    public Float add(float baseValue, float difference) {
50
-       return null;
52
+       return (float) (baseValue + difference);
51
    }
53
    }
52
 
54
 
53
    /**
55
    /**
56
     * @return sum of `baseValue` and `difference`
58
     * @return sum of `baseValue` and `difference`
57
     */
59
     */
58
    public Double add(double baseValue, double difference) {
60
    public Double add(double baseValue, double difference) {
59
-       return null;
61
+       return (double) (baseValue + difference);
60
    }
62
    }
61
 
63
 
62
    /**
64
    /**
65
     * @return difference between `baseValue` and `difference`
67
     * @return difference between `baseValue` and `difference`
66
     */
68
     */
67
    public Integer subtract(int baseValue, int difference) {
69
    public Integer subtract(int baseValue, int difference) {
68
-       return null;
70
+       return baseValue - difference;
69
    }
71
    }
70
 
72
 
71
    /**
73
    /**
74
     * @return difference between `baseValue` and `difference`
76
     * @return difference between `baseValue` and `difference`
75
     */
77
     */
76
    public Long subtract(long baseValue, long difference) {
78
    public Long subtract(long baseValue, long difference) {
77
-       return null;
79
+       return baseValue - difference;
78
    }
80
    }
79
 
81
 
80
    /**
82
    /**
83
     * @return difference between `baseValue` and `difference`
85
     * @return difference between `baseValue` and `difference`
84
     */
86
     */
85
    public Short subtract(short baseValue, short difference) {
87
    public Short subtract(short baseValue, short difference) {
86
-       return null;
88
+       return (short)(baseValue - difference);
87
    }
89
    }
88
 
90
 
89
    /**
91
    /**
92
     * @return difference between `baseValue` and `difference`
94
     * @return difference between `baseValue` and `difference`
93
     */
95
     */
94
    public Byte subtract(byte baseValue, byte difference) {
96
    public Byte subtract(byte baseValue, byte difference) {
95
-       return null;
97
+       return (byte)(baseValue - difference);
96
    }
98
    }
97
 
99
 
98
    /**
100
    /**
101
     * @return difference between `baseValue` and `difference`
103
     * @return difference between `baseValue` and `difference`
102
     */
104
     */
103
    public Float subtract(float baseValue, float difference) {
105
    public Float subtract(float baseValue, float difference) {
104
-       return null;
106
+       return (float)(baseValue - difference);
105
    }
107
    }
106
 
108
 
107
    /**
109
    /**
110
     * @return difference between `baseValue` and `difference`
112
     * @return difference between `baseValue` and `difference`
111
     */
113
     */
112
    public Double subtract(double baseValue, double difference) {
114
    public Double subtract(double baseValue, double difference) {
113
-       return null;
115
+       return (double)(baseValue - difference);
114
    }
116
    }
115
 
117
 
116
 
118
 
120
     * @return division of `dividend` by `divisor
122
     * @return division of `dividend` by `divisor
121
     */
123
     */
122
    public Integer divide(int dividend, int divisor) {
124
    public Integer divide(int dividend, int divisor) {
123
-       return null;
125
+       return dividend / divisor;
124
    }
126
    }
125
 
127
 
126
    /**
128
    /**
129
     * @return division of `dividend` by `divisor
131
     * @return division of `dividend` by `divisor
130
     */
132
     */
131
    public Long divide(long dividend, long divisor) {
133
    public Long divide(long dividend, long divisor) {
132
-       return null;
134
+       return dividend / divisor;
133
    }
135
    }
134
 
136
 
135
    /**
137
    /**
138
     * @return division of `dividend` by `divisor
140
     * @return division of `dividend` by `divisor
139
     */
141
     */
140
    public Short divide(short dividend, short divisor) {
142
    public Short divide(short dividend, short divisor) {
141
-       return null;
143
+       return (short)(dividend / divisor);
142
    }
144
    }
143
 
145
 
144
    /**
146
    /**
147
     * @return division of `dividend` by `divisor
149
     * @return division of `dividend` by `divisor
148
     */
150
     */
149
    public Byte divide(byte dividend, byte divisor) {
151
    public Byte divide(byte dividend, byte divisor) {
150
-       return null;
152
+       return (byte)(dividend / divisor);
151
    }
153
    }
152
 
154
 
153
    /**
155
    /**
156
     * @return division of `dividend` by `divisor
158
     * @return division of `dividend` by `divisor
157
     */
159
     */
158
    public Float divide(float dividend, float divisor) {
160
    public Float divide(float dividend, float divisor) {
159
-       return null;
161
+       return (float)(dividend / divisor);
160
    }
162
    }
161
 
163
 
162
    /**
164
    /**
165
     * @return division of `dividend` by `divisor
167
     * @return division of `dividend` by `divisor
166
     */
168
     */
167
    public Double divide(double dividend, double divisor) {
169
    public Double divide(double dividend, double divisor) {
168
-       return null;
170
+       return (double)(dividend / divisor);
169
    }
171
    }
170
 
172
 
171
 
173
 
175
     * @return product of `multiplicand` by `multiplier`
177
     * @return product of `multiplicand` by `multiplier`
176
     */
178
     */
177
    public Integer multiply(int multiplicand, int multiplier) {
179
    public Integer multiply(int multiplicand, int multiplier) {
178
-       return null;
180
+       return multiplicand * multiplier;
179
    }
181
    }
180
 
182
 
181
    /**
183
    /**
184
     * @return product of `multiplicand` by `multiplier`
186
     * @return product of `multiplicand` by `multiplier`
185
     */
187
     */
186
    public Long multiply(long multiplicand, long multiplier) {
188
    public Long multiply(long multiplicand, long multiplier) {
187
-       return null;
189
+       return multiplicand * multiplier;
188
    }
190
    }
189
 
191
 
190
    /**
192
    /**
193
     * @return product of `multiplicand` by `multiplier`
195
     * @return product of `multiplicand` by `multiplier`
194
     */
196
     */
195
    public Short multiply(short multiplicand, short multiplier) {
197
    public Short multiply(short multiplicand, short multiplier) {
196
-       return null;
198
+       return (short)(multiplicand * multiplier);
197
    }
199
    }
198
    /**
200
    /**
199
     * @param multiplicand value to be multiplied
201
     * @param multiplicand value to be multiplied
201
     * @return product of `multiplicand` by `multiplier`
203
     * @return product of `multiplicand` by `multiplier`
202
     */
204
     */
203
    public Byte multiply(byte multiplicand, byte multiplier) {
205
    public Byte multiply(byte multiplicand, byte multiplier) {
204
-       return null;
206
+       return (byte)(multiplicand * multiplier);
205
    }
207
    }
206
 
208
 
207
    /**
209
    /**
210
     * @return product of `multiplicand` by `multiplier`
212
     * @return product of `multiplicand` by `multiplier`
211
     */
213
     */
212
    public Float multiply(float multiplicand, float multiplier) {
214
    public Float multiply(float multiplicand, float multiplier) {
213
-       return null;
215
+       return (float)(multiplicand * multiplier);
214
    }
216
    }
215
 
217
 
216
    /**
218
    /**
219
     * @return product of `multiplicand` by `multiplier`
221
     * @return product of `multiplicand` by `multiplier`
220
     */
222
     */
221
    public Double multiply(double multiplicand, double multiplier) {
223
    public Double multiply(double multiplicand, double multiplier) {
222
-       return null;
224
+       return (double)(multiplicand * multiplier);
223
    }
225
    }
224
 
226
 
225
 
227
 
227
      * @return true
229
      * @return true
228
     */
230
     */
229
    public Boolean returnTrue() {
231
    public Boolean returnTrue() {
230
-       return null;
232
+       return true;
231
    }
233
    }
232
 
234
 
233
    /**
235
    /**
234
     * @return false
236
     * @return false
235
     */
237
     */
236
    public Boolean returnFalse() {
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
     * @return true if `x` is greater than `y`
10
     * @return true if `x` is greater than `y`
11
     */
11
     */
12
    public Boolean isGreaterThan(int x, int y) {
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
     * @return true if `x` is less than `y`
23
     * @return true if `x` is less than `y`
20
     */
24
     */
21
    public Boolean isLessThan(int x, int y) {
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
     * @return true if `x` is greater than or equal to `y`
36
     * @return true if `x` is greater than or equal to `y`
29
     */
37
     */
30
    public Boolean isGreaterThanOrEqualTo(int x, int y) {
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
     * @return true if `x` is less than or equal to `y`
49
     * @return true if `x` is less than or equal to `y`
38
     */
50
     */
39
    public Boolean isLessThanOrEqualTo(int x, int y) {
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
      * @return `Hello World` as a string
8
      * @return `Hello World` as a string
9
      */
9
      */
10
     public String getHelloWorld() {
10
     public String getHelloWorld() {
11
-        return null;
11
+        return "Hello World";
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 String concatenation(String firstSegment, String secondSegment){
19
     public String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+        return firstSegment + secondSegment;
21
     }
21
     }
22
 
22
 
23
     /**
23
     /**
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
27
      */
28
     public String concatenation(int firstSegment, String secondSegment){
28
     public String concatenation(int firstSegment, String secondSegment){
29
-        return null;
29
+        return firstSegment + secondSegment;
30
     }
30
     }
31
 
31
 
32
     /**
32
     /**
34
      * @return the first 3 characters of `input`
34
      * @return the first 3 characters of `input`
35
      */
35
      */
36
     public String getPrefix(String input){
36
     public String getPrefix(String input){
37
-        return null;
37
+        return input.substring(0, 3);
38
+     
39
+  
38
     }
40
     }
39
 
41
 
40
     /**
42
     /**
42
      * @return the last 3 characters of `input`
44
      * @return the last 3 characters of `input`
43
      */
45
      */
44
     public String getSuffix(String input){
46
     public String getSuffix(String input){
45
-        return null;
47
+        return input.substring(input.length()-3);
46
     }
48
     }
47
 
49
 
48
     /**
50
     /**
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
53
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
54
      */
53
     public Boolean compareTwoStrings(String inputValue, String comparableValue){
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
      * @return the middle character of `inputValue`
65
      * @return the middle character of `inputValue`
60
      */
66
      */
61
     public Character getMiddleCharacter(String inputValue){
67
     public Character getMiddleCharacter(String inputValue){
62
-        return null;
63
-    }
68
+        return inputValue.charAt((inputValue.length() - 1) / 2);
69
+}
64
 
70
 
65
     /**
71
     /**
66
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
72
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67
      * @return the first sequence of characters
73
      * @return the first sequence of characters
68
      */
74
      */
69
     public String getFirstWord(String spaceDelimitedString){
75
     public String getFirstWord(String spaceDelimitedString){
70
-        return null;
76
+        return spaceDelimitedString.split(" ")[0];
71
     }
77
     }
72
 
78
 
73
     /**
79
     /**
75
      * @return the second word of a string delimited by spaces.
81
      * @return the second word of a string delimited by spaces.
76
      */
82
      */
77
     public String getSecondWord(String spaceDelimitedString){
83
     public String getSecondWord(String spaceDelimitedString){
78
-        return null;
84
+        return spaceDelimitedString.split(" ")[1];
79
     }
85
     }
80
 
86
 
81
     /**
87
     /**
83
      * @return an identical string with characters in reverse order.
89
      * @return an identical string with characters in reverse order.
84
      */
90
      */
85
     public String reverse(String stringToReverse){
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
      * @return an identical string with spaces removed.
98
      * @return an identical string with spaces removed.
92
      */
99
      */
93
     public String removeWhitespace(String input){
100
     public String removeWhitespace(String input){
94
-        return null;
101
+        return input.replaceAll("\\s+", "");
95
     }
102
     }
96
 
103
 
97
     /**
104
     /**
99
      * @return an identical string with spaces in the front and end removed.
106
      * @return an identical string with spaces in the front and end removed.
100
      */
107
      */
101
     public String trim(String input){
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 查看文件