Yesoda Sanka 6 anni fa
parent
commit
abdc91984f

BIN
MathUtilities.class Vedi File


+ 5
- 5
MathUtilities.ctxt Vedi File

@@ -1,7 +1,7 @@
1 1
 #BlueJ class context
2 2
 comment0.target=MathUtilities
3 3
 comment0.text=\n\ Created\ by\ dan\ on\ 6/14/17.\n
4
-comment1.params=baseValue\ difference
4
+comment1.params=baseValue\ addedValue
5 5
 comment1.target=java.lang.Integer\ add(int,\ int)
6 6
 comment1.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ add\ to\ starting\ value\n\ @return\ sum\ of\ `baseValue`\ and\ `difference`\n
7 7
 comment10.params=baseValue\ difference
@@ -58,16 +58,16 @@ comment25.text=\n\ @return\ true\n
58 58
 comment26.params=
59 59
 comment26.target=java.lang.Boolean\ returnFalse()
60 60
 comment26.text=\n\ @return\ false\n
61
-comment3.params=baseValue\ difference
61
+comment3.params=baseValue\ addedValue
62 62
 comment3.target=java.lang.Short\ add(short,\ short)
63 63
 comment3.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ add\ to\ starting\ value\n\ @return\ sum\ of\ `baseValue`\ and\ `difference`\n
64
-comment4.params=baseValue\ difference
64
+comment4.params=baseValue\ addedValue
65 65
 comment4.target=java.lang.Byte\ add(byte,\ byte)
66 66
 comment4.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ add\ to\ starting\ value\n\ @return\ sum\ of\ `baseValue`\ and\ `difference`\n
67
-comment5.params=baseValue\ difference
67
+comment5.params=baseValue\ addedValue
68 68
 comment5.target=java.lang.Float\ add(float,\ float)
69 69
 comment5.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ add\ to\ starting\ value\n\ @return\ sum\ of\ `baseValue`\ and\ `difference`\n
70
-comment6.params=baseValue\ difference
70
+comment6.params=baseValue\ addedValue
71 71
 comment6.target=java.lang.Double\ add(double,\ double)
72 72
 comment6.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ add\ to\ starting\ value\n\ @return\ sum\ of\ `baseValue`\ and\ `difference`\n
73 73
 comment7.params=baseValue\ difference

+ 37
- 31
MathUtilities.java Vedi File

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

BIN
MathUtilitiesTest.class Vedi File


+ 19
- 27
MathUtilitiesTest.java Vedi File

@@ -1,7 +1,5 @@
1
- 
2 1
 
3 2
 import org.junit.Test;
4
-
5 3
 import static org.junit.Assert.*;
6 4
 /**
7 5
  * Created by dan on 6/14/17.
@@ -16,10 +14,11 @@ public class MathUtilitiesTest {
16 14
         int addedValue = 7;
17 15
         int expected = 27;
18 16
         // : When
19
-        int actual = primativeTypes.add(baseValue, addedValue);
17
+        int actual = primativeTypes.add(baseValue,addedValue);
20 18
         // : Then
21 19
         assertEquals(expected,actual);
22 20
     }
21
+
23 22
     @Test
24 23
     public void testAdditions1() {
25 24
         // : Given
@@ -31,6 +30,7 @@ public class MathUtilitiesTest {
31 30
         // : Then
32 31
         assertEquals(expected,actual);
33 32
     }
33
+
34 34
     @Test
35 35
     public void testAdditions2() {
36 36
         // : Given
@@ -54,6 +54,7 @@ public class MathUtilitiesTest {
54 54
         // : Then
55 55
         assertEquals(expected,actual);
56 56
     }
57
+
57 58
     @Test
58 59
     public void testAdditions5() {
59 60
         // : Given
@@ -85,14 +86,6 @@ public class MathUtilitiesTest {
85 86
 
86 87
 
87 88
 
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96 89
     @Test
97 90
     public void testSubtractions(){
98 91
         // : Given
@@ -104,6 +97,7 @@ public class MathUtilitiesTest {
104 97
         // : Then
105 98
         assertEquals(expectedInt,actualInt);
106 99
     }
100
+
107 101
     @Test
108 102
     public void testSubtractions1() {
109 103
         // : Given
@@ -115,6 +109,7 @@ public class MathUtilitiesTest {
115 109
         // : Then
116 110
         assertEquals(expectedLong,actualLong);
117 111
     }
112
+
118 113
     @Test
119 114
     public void testSubtractions2() {
120 115
         // : Given
@@ -126,6 +121,7 @@ public class MathUtilitiesTest {
126 121
         // : Then
127 122
         assertEquals(expectedShort,actualShort);
128 123
     }
124
+
129 125
     @Test
130 126
     public void testSubtractions3() {
131 127
         // : Given
@@ -137,6 +133,7 @@ public class MathUtilitiesTest {
137 133
         // : Then
138 134
         assertEquals(expectedByte,actualByte);
139 135
     }
136
+
140 137
     @Test
141 138
     public void testSubtractions4() {
142 139
         // : Given
@@ -148,6 +145,7 @@ public class MathUtilitiesTest {
148 145
         // : Then
149 146
         assertEquals(expectedFloat,actualFloat, 0.005);
150 147
     }
148
+
151 149
     @Test
152 150
     public void testSubtractions5() {
153 151
         // : Given
@@ -166,13 +164,6 @@ public class MathUtilitiesTest {
166 164
 
167 165
 
168 166
 
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176 167
     @Test
177 168
     public void testDivision(){
178 169
         // : Given
@@ -184,6 +175,7 @@ public class MathUtilitiesTest {
184 175
         // : Then
185 176
         assertEquals(expectedInt,actualInt);
186 177
     }
178
+
187 179
     @Test
188 180
     public void testDivision1() {
189 181
         // : Given
@@ -195,6 +187,7 @@ public class MathUtilitiesTest {
195 187
         // : Then
196 188
         assertEquals(expectedLong,actualLong);
197 189
     }
190
+
198 191
     @Test
199 192
     public void testDivision2() {
200 193
         // : Given
@@ -207,6 +200,7 @@ public class MathUtilitiesTest {
207 200
         assertEquals(expectedShort,actualShort);
208 201
 
209 202
     }
203
+
210 204
     @Test
211 205
     public void testDivision3() {
212 206
         // : Given
@@ -218,6 +212,7 @@ public class MathUtilitiesTest {
218 212
         // : Then
219 213
         assertEquals(expectedByte,actualByte);
220 214
     }
215
+
221 216
     @Test
222 217
     public void testDivision4() {
223 218
         // : Given
@@ -229,6 +224,7 @@ public class MathUtilitiesTest {
229 224
         // : Then
230 225
         assertEquals(expectedFloat,actualFloat, 0);
231 226
     }
227
+
232 228
     @Test
233 229
     public void testDivision5() {
234 230
         // : Given
@@ -249,15 +245,6 @@ public class MathUtilitiesTest {
249 245
 
250 246
 
251 247
 
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261 248
     @Test
262 249
     public void testMultiplication(){
263 250
         // : Given
@@ -269,6 +256,7 @@ public class MathUtilitiesTest {
269 256
         // : Then
270 257
         assertEquals(expectedInt,actualInt);
271 258
     }
259
+
272 260
     @Test
273 261
     public void testMultiplication1() {
274 262
         // : Given
@@ -280,6 +268,7 @@ public class MathUtilitiesTest {
280 268
         // : Then
281 269
         assertEquals(expectedLong, actualLong);
282 270
     }
271
+
283 272
     @Test
284 273
     public void testMultiplication2() {
285 274
         // : Given
@@ -291,6 +280,7 @@ public class MathUtilitiesTest {
291 280
         // : Then
292 281
         assertEquals(expectedShort, actualShort);
293 282
     }
283
+
294 284
     @Test
295 285
     public void testMultiplication3() {
296 286
         // : Given
@@ -302,6 +292,7 @@ public class MathUtilitiesTest {
302 292
         // : Then
303 293
         assertEquals(expectedByte, actualByte);
304 294
     }
295
+
305 296
     @Test
306 297
     public void testMultiplication4() {
307 298
         // : Given
@@ -313,6 +304,7 @@ public class MathUtilitiesTest {
313 304
         // : Then
314 305
         assertEquals(expectedFloat, actualFloat, 0);
315 306
     }
307
+
316 308
     @Test
317 309
     public void testMultiplication5() {
318 310
         // : Given

BIN
PredicateUtilities.class Vedi File


+ 28
- 5
PredicateUtilities.java Vedi File

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

BIN
StringUtilities.class Vedi File


+ 48
- 13
StringUtilities.java Vedi File

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
@@ -8,7 +7,7 @@ public class StringUtilities {
8 7
      * @return `Hello World` as a string
9 8
      */
10 9
     public static String getHelloWorld() {
11
-        return null;
10
+        return "Hello World";
12 11
     }
13 12
 
14 13
     /**
@@ -17,7 +16,10 @@ public class StringUtilities {
17 16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 17
      */
19 18
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
19
+        //StringBuilder sb=new StringBuilder().append(firstSegment).append(secondSegment);
20
+        //return sb.toString();
21
+        return (firstSegment + secondSegment);
22
+
21 23
     }
22 24
 
23 25
     /**
@@ -26,7 +28,8 @@ public class StringUtilities {
26 28
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 29
      */
28 30
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
31
+        StringBuilder sum=new StringBuilder().append(firstSegment).append(secondSegment);
32
+        return sum.toString();
30 33
     }
31 34
 
32 35
     /**
@@ -34,7 +37,8 @@ public class StringUtilities {
34 37
      * @return the first 3 characters of `input`
35 38
      */
36 39
     public static String getPrefix(String input){
37
-        return null;
40
+        String str=input.substring(0,3);
41
+        return str;
38 42
     }
39 43
 
40 44
     /**
@@ -42,7 +46,8 @@ public class StringUtilities {
42 46
      * @return the last 3 characters of `input`
43 47
      */
44 48
     public static String getSuffix(String input){
45
-        return null;
49
+        String str=input.substring(input.length() - 3);
50
+        return str;
46 51
     }
47 52
 
48 53
     /**
@@ -51,7 +56,10 @@ public class StringUtilities {
51 56
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 57
      */
53 58
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
59
+
60
+        boolean val =inputValue.equalsIgnoreCase(comparableValue);
61
+        return val;
62
+
55 63
     }
56 64
 
57 65
     /**
@@ -59,23 +67,47 @@ public class StringUtilities {
59 67
      * @return the middle character of `inputValue`
60 68
      */
61 69
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
70
+        int len = inputValue.length();
71
+        char ch[]=inputValue.toCharArray();
72
+        int c = len/2;
73
+          if(len%2 == 0)
74
+          {
75
+              return ch [c-1];
76
+            }          
77
+        else
78
+        {
79
+            
80
+            return ch[c];
81
+        } 
82
+      
63 83
     }
64
-
65 84
     /**
66 85
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 86
      * @return the first sequence of characters
68 87
      */
69 88
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
89
+        String[] result=spaceDelimitedString.split(" ");
90
+        /*for(int i = 0; i < spaceDelimitedString.length(); i++)
91
+        {
92
+            if(spaceDelimitedString.charAt(i) == ' ')
93
+            {
94
+                result = spaceDelimitedString.substring(0, i);
95
+                break;
96
+            }
97
+        }*/
98
+        return result[0];
99
+
71 100
     }
72 101
 
73 102
     /**
74 103
      * @param spaceDelimitedString a string delimited by spaces
75 104
      * @return the second word of a string delimited by spaces.
76 105
      */
77
-    public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
106
+    public static String getSecondWord(String spaceDelimitedString)
107
+
108
+    {
109
+       String[] str=spaceDelimitedString.split(" ");
110
+       return str[1];
79 111
     }
80 112
 
81 113
     /**
@@ -83,6 +115,9 @@ public class StringUtilities {
83 115
      * @return an identical string with characters in reverse order.
84 116
      */
85 117
     public static String reverse(String stringToReverse){
86
-        return null;
118
+        StringBuilder a = new StringBuilder(stringToReverse);
119
+        String str=a.reverse().toString();
120
+
121
+        return str;
87 122
     }
88 123
 }

+ 9
- 6
package.bluej Vedi File

@@ -1,10 +1,13 @@
1 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
+dependency1.from=MathUtilitiesTest
3
+dependency1.to=MathUtilities
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=714
6
+editor.fx.0.width=800
7
+editor.fx.0.x=240
8
+editor.fx.0.y=23
6 9
 objectbench.height=129
7
-objectbench.width=1171
10
+objectbench.width=698
8 11
 package.divider.horizontal=0.6
9 12
 package.divider.vertical=0.7490774907749077
10 13
 package.editor.height=399
@@ -13,7 +16,7 @@ package.editor.x=59
13 16
 package.editor.y=63
14 17
 package.frame.height=600
15 18
 package.frame.width=1195
16
-package.numDependencies=0
19
+package.numDependencies=1
17 20
 package.numTargets=6
18 21
 package.showExtends=true
19 22
 package.showUses=true