#36 Lab Completed

Open
chu1ta26 wants to merge 3 commits from chu1ta26/CR-MicroLabs-JavaFundamentals-DanDoBetterDrills:master into master
8 changed files with 88 additions and 56 deletions
  1. BIN
      MathUtilities.class
  2. 43
    31
      MathUtilities.java
  3. BIN
      PredicateUtilities.class
  4. 4
    4
      PredicateUtilities.java
  5. BIN
      StringUtilities.class
  6. 1
    1
      StringUtilities.ctxt
  7. 32
    12
      StringUtilities.java
  8. 8
    8
      package.bluej

BIN
MathUtilities.class View File


+ 43
- 31
MathUtilities.java View File

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

BIN
PredicateUtilities.class View File


+ 4
- 4
PredicateUtilities.java View File

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

BIN
StringUtilities.class View File


+ 1
- 1
StringUtilities.ctxt View File

@@ -27,7 +27,7 @@ comment7.target=java.lang.Character\ getMiddleCharacter(java.lang.String)
27 27
 comment7.text=\n\ @param\ inputValue\ the\ value\ input\ from\ user\n\ @return\ the\ middle\ character\ of\ `inputValue`\n
28 28
 comment8.params=spaceDelimitedString
29 29
 comment8.target=java.lang.String\ getFirstWord(java.lang.String)
30
-comment8.text=\n\ @param\ spaceDelimitedString\ a\ string,\ representative\ of\ a\ sentence,\ containing\ spaces\n\ @return\ the\ first\ sequence\ of\ characters\n
30
+comment8.text=\n\ \ \ \ a\ *\ @param\ spaceDelimitedString\ a\ string,\ representative\ of\ a\ sentence,\ containing\ spaces\n\ @return\ the\ first\ sequence\ of\ characters\n
31 31
 comment9.params=spaceDelimitedString
32 32
 comment9.target=java.lang.String\ getSecondWord(java.lang.String)
33 33
 comment9.text=\n\ @param\ spaceDelimitedString\ a\ string\ delimited\ by\ spaces\n\ @return\ the\ second\ word\ of\ a\ string\ delimited\ by\ spaces.\n

+ 32
- 12
StringUtilities.java View 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,7 @@ 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
+        return firstSegment + secondSegment;
21 20
     }
22 21
 
23 22
     /**
@@ -26,7 +25,7 @@ public class StringUtilities {
26 25
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 26
      */
28 27
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
28
+        return firstSegment  + secondSegment;
30 29
     }
31 30
 
32 31
     /**
@@ -34,7 +33,7 @@ public class StringUtilities {
34 33
      * @return the first 3 characters of `input`
35 34
      */
36 35
     public static String getPrefix(String input){
37
-        return null;
36
+        return input.substring(0,3);
38 37
     }
39 38
 
40 39
     /**
@@ -42,7 +41,8 @@ public class StringUtilities {
42 41
      * @return the last 3 characters of `input`
43 42
      */
44 43
     public static String getSuffix(String input){
45
-        return null;
44
+        return input.substring(input.length() - 3);
45
+       
46 46
     }
47 47
 
48 48
     /**
@@ -51,7 +51,10 @@ public class StringUtilities {
51 51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 52
      */
53 53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
54
+        if (inputValue.equals(comparableValue)){
55
+                return true;}
56
+        
57
+        return false;
55 58
     }
56 59
 
57 60
     /**
@@ -59,15 +62,26 @@ public class StringUtilities {
59 62
      * @return the middle character of `inputValue`
60 63
      */
61 64
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
65
+        int remeinder = 0;
66
+        int leng = inputValue.length();
67
+        if ( inputValue.length() % 2 == 0) {
68
+            remeinder = leng /2 -1;
69
+             
70
+        } else { remeinder = leng /2 ; }
71
+        
72
+        
73
+               
74
+        return inputValue.charAt(remeinder);
75
+        
63 76
     }
64 77
 
65 78
     /**
66
-     * @param spaceDelimitedString a string, representative of a sentence, containing spaces
79
+    a * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 80
      * @return the first sequence of characters
68 81
      */
69 82
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
83
+        
84
+        return spaceDelimitedString.split(" ")[0];
71 85
     }
72 86
 
73 87
     /**
@@ -75,7 +89,8 @@ public class StringUtilities {
75 89
      * @return the second word of a string delimited by spaces.
76 90
      */
77 91
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
92
+       
93
+        return spaceDelimitedString.split(" ")[1];
79 94
     }
80 95
 
81 96
     /**
@@ -83,6 +98,11 @@ public class StringUtilities {
83 98
      * @return an identical string with characters in reverse order.
84 99
      */
85 100
     public static String reverse(String stringToReverse){
86
-        return null;
101
+        String temp = "";
102
+        for(int i = stringToReverse.length () - 1; i >=0; i--){
103
+            temp += stringToReverse.charAt (i); 
104
+        }
105
+        
106
+        return temp ;
87 107
     }
88 108
 }

+ 8
- 8
package.bluej View File

@@ -3,13 +3,13 @@ editor.fx.0.height=0
3 3
 editor.fx.0.width=0
4 4
 editor.fx.0.x=0
5 5
 editor.fx.0.y=0
6
-objectbench.height=129
6
+objectbench.height=128
7 7
 objectbench.width=1171
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.7490774907749077
10
-package.editor.height=399
9
+package.divider.vertical=0.7509225092250923
10
+package.editor.height=400
11 11
 package.editor.width=1069
12
-package.editor.x=59
12
+package.editor.x=85
13 13
 package.editor.y=63
14 14
 package.frame.height=600
15 15
 package.frame.width=1195
@@ -37,13 +37,13 @@ target2.type=UnitTestTargetJunit4
37 37
 target2.width=140
38 38
 target2.x=490
39 39
 target2.y=70
40
-target3.height=50
40
+target3.height=160
41 41
 target3.name=MathUtilities
42 42
 target3.showInterface=false
43 43
 target3.type=ClassTarget
44
-target3.width=100
45
-target3.x=60
46
-target3.y=150
44
+target3.width=190
45
+target3.x=40
46
+target3.y=200
47 47
 target4.height=50
48 48
 target4.name=StringUtilities
49 49
 target4.showInterface=false