Преглед на файлове

Edited code to pass all tests

Akeem Cherry преди 6 години
родител
ревизия
01001b5d4c
променени са 7 файла, в които са добавени 64 реда и са изтрити 54 реда
  1. BIN
      MathUtilities.class
  2. 35
    26
      MathUtilities.java
  3. BIN
      PredicateUtilities.class
  4. 4
    4
      PredicateUtilities.java
  5. BIN
      StringUtilities.class
  6. 11
    10
      StringUtilities.java
  7. 14
    14
      package.bluej

BIN
MathUtilities.class Целия файл


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

BIN
PredicateUtilities.class Целия файл


+ 4
- 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
+        return x > y;
14
     }
14
     }
15
 
15
 
16
     /**
16
     /**
19
      * @return true if `x` is less than `y`
19
      * @return true if `x` is less than `y`
20
      */
20
      */
21
     public Boolean isLessThan(int x, int y) {
21
     public Boolean isLessThan(int x, int y) {
22
-        return null;
22
+        return x < y;
23
     }
23
     }
24
 
24
 
25
     /**
25
     /**
28
      * @return true if `x` is greater than or equal to `y`
28
      * @return true if `x` is greater than or equal to `y`
29
      */
29
      */
30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
31
+        return x >= y;
32
     }
32
     }
33
 
33
 
34
     /**
34
     /**
37
      * @return true if `x` is less than or equal to `y`
37
      * @return true if `x` is less than or equal to `y`
38
      */
38
      */
39
     public Boolean isLessThanOrEqualTo(int x, int y) {
39
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
40
+        return x <= y;
41
     }
41
     }
42
 }
42
 }

BIN
StringUtilities.class Целия файл


+ 11
- 10
StringUtilities.java Целия файл

8
      * @return `Hello World` as a string
8
      * @return `Hello World` as a string
9
      */
9
      */
10
     public static String getHelloWorld() {
10
     public static 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 static String concatenation(String firstSegment, String secondSegment){
19
     public static 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 static String concatenation(int firstSegment, String secondSegment){
28
     public static 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 static String getPrefix(String input){
36
     public static String getPrefix(String input){
37
-        return null;
37
+        return input.substring(0,3);
38
     }
38
     }
39
 
39
 
40
     /**
40
     /**
42
      * @return the last 3 characters of `input`
42
      * @return the last 3 characters of `input`
43
      */
43
      */
44
     public static String getSuffix(String input){
44
     public static String getSuffix(String input){
45
-        return null;
45
+        return input.substring(2,5);
46
     }
46
     }
47
 
47
 
48
     /**
48
     /**
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
52
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
54
+        return inputValue.equals(comparableValue);
55
     }
55
     }
56
 
56
 
57
     /**
57
     /**
59
      * @return the middle character of `inputValue`
59
      * @return the middle character of `inputValue`
60
      */
60
      */
61
     public static Character getMiddleCharacter(String inputValue){
61
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
62
+        return inputValue.charAt((inputValue.length()-1)/2);
63
     }
63
     }
64
 
64
 
65
     /**
65
     /**
67
      * @return the first sequence of characters
67
      * @return the first sequence of characters
68
      */
68
      */
69
     public static String getFirstWord(String spaceDelimitedString){
69
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
70
+        return (spaceDelimitedString + " ").split(" ")[0];
71
     }
71
     }
72
 
72
 
73
     /**
73
     /**
75
      * @return the second word of a string delimited by spaces.
75
      * @return the second word of a string delimited by spaces.
76
      */
76
      */
77
     public static String getSecondWord(String spaceDelimitedString){
77
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
78
+        return (spaceDelimitedString + " ").split(" ")[1];
79
     }
79
     }
80
 
80
 
81
     /**
81
     /**
83
      * @return an identical string with characters in reverse order.
83
      * @return an identical string with characters in reverse order.
84
      */
84
      */
85
     public static String reverse(String stringToReverse){
85
     public static String reverse(String stringToReverse){
86
-        return null;
86
+        String rev = new StringBuilder(stringToReverse).reverse().toString();
87
+        return rev;
87
     }
88
     }
88
 }
89
 }

+ 14
- 14
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
+editor.fx.0.height=714
3
+editor.fx.0.width=800
4
+editor.fx.0.x=447
5
+editor.fx.0.y=25
6
 objectbench.height=129
6
 objectbench.height=129
7
 objectbench.width=1171
7
 objectbench.width=1171
8
 package.divider.horizontal=0.6
8
 package.divider.horizontal=0.6
45
 target3.x=60
45
 target3.x=60
46
 target3.y=150
46
 target3.y=150
47
 target4.height=50
47
 target4.height=50
48
-target4.name=StringUtilities
48
+target4.name=PredicateUtilitiesTest
49
 target4.showInterface=false
49
 target4.showInterface=false
50
-target4.type=ClassTarget
51
-target4.width=110
52
-target4.x=500
53
-target4.y=130
50
+target4.type=UnitTestTargetJunit4
51
+target4.width=160
52
+target4.x=260
53
+target4.y=50
54
 target5.height=50
54
 target5.height=50
55
-target5.name=PredicateUtilitiesTest
55
+target5.name=StringUtilities
56
 target5.showInterface=false
56
 target5.showInterface=false
57
-target5.type=UnitTestTargetJunit4
58
-target5.width=160
59
-target5.x=260
60
-target5.y=50
57
+target5.type=ClassTarget
58
+target5.width=110
59
+target5.x=500
60
+target5.y=130
61
 target6.height=50
61
 target6.height=50
62
 target6.name=MathUtilitiesTest
62
 target6.name=MathUtilitiesTest
63
 target6.showInterface=false
63
 target6.showInterface=false