Browse Source

DanDoBetterDrills

Soujanya Buragapu 6 years ago
parent
commit
cc83f7d249
8 changed files with 193 additions and 102 deletions
  1. BIN
      MathUtilities.class
  2. 4
    5
      MathUtilities.ctxt
  3. 80
    60
      MathUtilities.java
  4. BIN
      PredicateUtilities.class
  5. 47
    11
      PredicateUtilities.java
  6. BIN
      StringUtilities.class
  7. 55
    19
      StringUtilities.java
  8. 7
    7
      package.bluej

BIN
MathUtilities.class View File


+ 4
- 5
MathUtilities.ctxt View File

@@ -1,9 +1,8 @@
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
-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 6
 comment10.params=baseValue\ difference
8 7
 comment10.target=java.lang.Byte\ subtract(byte,\ byte)
9 8
 comment10.text=\n\ @param\ baseValue\ \ starting\ value\n\ @param\ difference\ value\ to\ subtract\ from\ starting\ value\n\ @return\ difference\ between\ `baseValue`\ and\ `difference`\n
@@ -58,16 +57,16 @@ comment25.text=\n\ @return\ true\n
58 57
 comment26.params=
59 58
 comment26.target=java.lang.Boolean\ returnFalse()
60 59
 comment26.text=\n\ @return\ false\n
61
-comment3.params=baseValue\ difference
60
+comment3.params=baseValue\ addedValue
62 61
 comment3.target=java.lang.Short\ add(short,\ short)
63 62
 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 63
 comment4.params=baseValue\ difference
65 64
 comment4.target=java.lang.Byte\ add(byte,\ byte)
66 65
 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
66
+comment5.params=baseValue\ addedValue
68 67
 comment5.target=java.lang.Float\ add(float,\ float)
69 68
 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
69
+comment6.params=baseValue\ addedValue
71 70
 comment6.target=java.lang.Double\ add(double,\ double)
72 71
 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 72
 comment7.params=baseValue\ difference

+ 80
- 60
MathUtilities.java View File

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

BIN
PredicateUtilities.class View File


+ 47
- 11
PredicateUtilities.java View File

@@ -1,16 +1,26 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
5 4
  */
6
-public class PredicateUtilities {
5
+public class PredicateUtilities
6
+{
7 7
     /**
8 8
      * @param x
9 9
      * @param y
10 10
      * @return true if `x` is greater than `y`
11 11
      */
12
-    public Boolean isGreaterThan(int x, int y) {
13
-        return null;
12
+    public Boolean isGreaterThan(int x, int y) 
13
+    {
14
+
15
+        if( x > y )
16
+        {
17
+            return true;
18
+        }
19
+        else 
20
+        {
21
+            return false;
22
+
23
+        }
14 24
     }
15 25
 
16 26
     /**
@@ -18,8 +28,16 @@ public class PredicateUtilities {
18 28
      * @param y
19 29
      * @return true if `x` is less than `y`
20 30
      */
21
-    public Boolean isLessThan(int x, int y) {
22
-        return null;
31
+    public Boolean isLessThan(int x, int y) 
32
+    {
33
+        if( x < y )
34
+        {
35
+            return true ;
36
+        }
37
+        else
38
+        {
39
+            return false;
40
+        }
23 41
     }
24 42
 
25 43
     /**
@@ -27,8 +45,17 @@ public class PredicateUtilities {
27 45
      * @param y
28 46
      * @return true if `x` is greater than or equal to `y`
29 47
      */
30
-    public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
48
+    public Boolean isGreaterThanOrEqualTo(int x, int y) 
49
+    {
50
+        if ( x >=y )
51
+        {
52
+            return true;
53
+        }
54
+        else
55
+        {
56
+            return false;
57
+        }
58
+
32 59
     }
33 60
 
34 61
     /**
@@ -36,7 +63,16 @@ public class PredicateUtilities {
36 63
      * @param y
37 64
      * @return true if `x` is less than or equal to `y`
38 65
      */
39
-    public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
66
+    public Boolean isLessThanOrEqualTo(int x, int y) 
67
+    {
68
+        if ( x <= y )
69
+        {
70
+            return true;
71
+        }
72
+        else
73
+        {
74
+            return false;
75
+        }
76
+
41 77
     }
42
-}
78
+}

BIN
StringUtilities.class View File


+ 55
- 19
StringUtilities.java View File

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

+ 7
- 7
package.bluej View File

@@ -1,18 +1,18 @@
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
+editor.fx.0.height=712
3
+editor.fx.0.width=956
4
+editor.fx.0.x=291
5
+editor.fx.0.y=23
6 6
 objectbench.height=129
7
-objectbench.width=1171
7
+objectbench.width=467
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.7490774907749077
10 10
 package.editor.height=399
11
-package.editor.width=1069
11
+package.editor.width=684
12 12
 package.editor.x=59
13 13
 package.editor.y=63
14 14
 package.frame.height=600
15
-package.frame.width=1195
15
+package.frame.width=810
16 16
 package.numDependencies=0
17 17
 package.numTargets=6
18 18
 package.showExtends=true