Parcourir la source

Lab DanDoBetterDrills

Nuridalia Hermandez il y a 6 ans
Parent
révision
a9739a2ea9
6 fichiers modifiés avec 65 ajouts et 33 suppressions
  1. BIN
      MathUtilities.class
  2. 30
    19
      MathUtilities.java
  3. BIN
      StringUtilities.class
  4. 1
    1
      StringUtilities.ctxt
  5. 30
    9
      StringUtilities.java
  6. 4
    4
      package.bluej

BIN
MathUtilities.class Voir le fichier


+ 30
- 19
MathUtilities.java Voir le fichier

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
@@ -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,8 +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
-        
42
-        return null;
41
+        int x = baseValue +difference;
42
+        return (byte) x;
43 43
     }
44 44
 
45 45
     /**
@@ -48,7 +48,8 @@ public class MathUtilities {
48 48
      * @return sum of `baseValue` and `difference`
49 49
      */
50 50
     public Float add(float baseValue, float difference) {
51
-        return null;
51
+
52
+        return baseValue + difference;
52 53
     }
53 54
 
54 55
     /**
@@ -75,7 +76,9 @@ public class MathUtilities {
75 76
      * @return difference between `baseValue` and `difference`
76 77
      */
77 78
     public Long subtract(long baseValue, long difference) {
78
-        return null;
79
+        double x = baseValue - difference;
80
+        return (long) x;
81
+
79 82
     }
80 83
 
81 84
     /**
@@ -84,7 +87,9 @@ public class MathUtilities {
84 87
      * @return difference between `baseValue` and `difference`
85 88
      */
86 89
     public Short subtract(short baseValue, short difference) {
87
-        return null;
90
+        int x = baseValue -difference;
91
+        return (short) x;
92
+
88 93
     }
89 94
 
90 95
     /**
@@ -93,7 +98,8 @@ public class MathUtilities {
93 98
      * @return difference between `baseValue` and `difference`
94 99
      */
95 100
     public Byte subtract(byte baseValue, byte difference) {
96
-        return null;
101
+        int x = baseValue -difference;
102
+        return (byte) x;
97 103
     }
98 104
 
99 105
     /**
@@ -102,7 +108,7 @@ public class MathUtilities {
102 108
      * @return difference between `baseValue` and `difference`
103 109
      */
104 110
     public Float subtract(float baseValue, float difference) {
105
-        return null;
111
+        return  baseValue- difference;
106 112
     }
107 113
 
108 114
     /**
@@ -114,7 +120,6 @@ public class MathUtilities {
114 120
         return baseValue - difference;
115 121
     }
116 122
 
117
-
118 123
     /**
119 124
      * @param dividend value to be divided
120 125
      * @param divisor value to divide by
@@ -139,7 +144,8 @@ public class MathUtilities {
139 144
      * @return division of `dividend` by `divisor
140 145
      */
141 146
     public Short divide(short dividend, short divisor) {
142
-        return null;
147
+        int x =dividend /divisor;
148
+        return (short) x;
143 149
     }
144 150
 
145 151
     /**
@@ -148,7 +154,8 @@ public class MathUtilities {
148 154
      * @return division of `dividend` by `divisor
149 155
      */
150 156
     public Byte divide(byte dividend, byte divisor) {
151
-        return null;
157
+         int x =dividend /divisor;
158
+        return (byte) x;
152 159
     }
153 160
 
154 161
     /**
@@ -169,7 +176,6 @@ public class MathUtilities {
169 176
         return dividend/divisor;
170 177
     }
171 178
 
172
-
173 179
     /**
174 180
      * @param multiplicand value to be multiplied
175 181
      * @param multiplier value to multiply by
@@ -185,7 +191,8 @@ public class MathUtilities {
185 191
      * @return product of `multiplicand` by `multiplier`
186 192
      */
187 193
     public Long multiply(long multiplicand, long multiplier) {
188
-        return null;
194
+         double x =multiplicand * multiplier;
195
+        return (long) x;
189 196
     }
190 197
 
191 198
     /**
@@ -194,15 +201,20 @@ public class MathUtilities {
194 201
      * @return product of `multiplicand` by `multiplier`
195 202
      */
196 203
     public Short multiply(short multiplicand, short multiplier) {
197
-        return null;
204
+         int x =multiplicand * multiplier;
205
+        return (short) x;
206
+    
198 207
     }
208
+
199 209
     /**
200 210
      * @param multiplicand value to be multiplied
201 211
      * @param multiplier value to multiply by
202 212
      * @return product of `multiplicand` by `multiplier`
203 213
      */
204 214
     public Byte multiply(byte multiplicand, byte multiplier) {
205
-        return null;
215
+         int x =multiplicand * multiplier;
216
+        return (byte) x;
217
+    
206 218
     }
207 219
 
208 220
     /**
@@ -211,7 +223,7 @@ public class MathUtilities {
211 223
      * @return product of `multiplicand` by `multiplier`
212 224
      */
213 225
     public Float multiply(float multiplicand, float multiplier) {
214
-        return null;
226
+        return multiplicand*multiplier;
215 227
     }
216 228
 
217 229
     /**
@@ -223,9 +235,8 @@ public class MathUtilities {
223 235
         return multiplicand * multiplier ;
224 236
     }
225 237
 
226
-
227 238
     /**
228
-      * @return true
239
+     * @return true
229 240
      */
230 241
     public Boolean returnTrue() {
231 242
         return true;

BIN
StringUtilities.class Voir le fichier


+ 1
- 1
StringUtilities.ctxt Voir le fichier

@@ -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

+ 30
- 9
StringUtilities.java Voir le fichier

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by dan on 6/14/17.
@@ -28,8 +27,7 @@ public class StringUtilities {
28 27
     public static String concatenation(int firstSegment, String secondSegment){
29 28
         String n = Integer.toString(firstSegment);
30 29
         return n + secondSegment;
31
-        
32
-        
30
+
33 31
     }
34 32
 
35 33
     /**
@@ -62,16 +60,30 @@ public class StringUtilities {
62 60
      * @return the middle character of `inputValue`
63 61
      */
64 62
     public static Character getMiddleCharacter(String inputValue){
65
-        return inputValue.charAt(inputValue.length()/2);
63
+        int post;
64
+        int leng;
65
+        if (inputValue.length()% 2 == 1){
66
+            post=inputValue.length()/2;
67
+            leng= 1;
68
+        } else {
69
+            post=inputValue.length()/2-1;
70
+            leng = 2; 
71
+        }
72
+        String mid = inputValue.substring(post, post
73
+                + leng);
74
+                char output = mid.charAt(0);
75
+        return output;//inputValue.charAt(inputValue.length()/2);
66 76
     }
67 77
 
68 78
     /**
69
-     * @param spaceDelimitedString a string, representative of a sentence, containing spaces
79
+    a * @param spaceDelimitedString a string, representative of a sentence, containing spaces
70 80
      * @return the first sequence of characters
71 81
      */
72 82
     public static String getFirstWord(String spaceDelimitedString){
73
-        String str= spaceDelimitedString.split(" ");
74
-        return  ;
83
+        int str= spaceDelimitedString.indexOf(" ");
84
+        String word = spaceDelimitedString.substring(0, str);
85
+
86
+        return word ;
75 87
     }
76 88
 
77 89
     /**
@@ -79,7 +91,11 @@ public class StringUtilities {
79 91
      * @return the second word of a string delimited by spaces.
80 92
      */
81 93
     public static String getSecondWord(String spaceDelimitedString){
82
-        return null;
94
+        /**int word = spaceDelimitedString.indexOf(" ");
95
+        int word1 = spaceDelimitedString.indexOf("", word );
96
+        String secondWord=spaceDelimitedString.substring(word , word1);
97
+        return secondWord;*/
98
+        return spaceDelimitedString.split(" ")[1];
83 99
     }
84 100
 
85 101
     /**
@@ -87,6 +103,11 @@ public class StringUtilities {
87 103
      * @return an identical string with characters in reverse order.
88 104
      */
89 105
     public static String reverse(String stringToReverse){
90
-        return null;
106
+        String reverse="";
107
+        for(int i = stringToReverse.length() - 1; i >= 0; i--)
108
+        {
109
+            reverse = reverse+ stringToReverse.charAt(i);
110
+        }
111
+        return reverse;
91 112
     }
92 113
 }

+ 4
- 4
package.bluej Voir le fichier

@@ -1,8 +1,8 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=712
3
-editor.fx.0.width=876
4
-editor.fx.0.x=365
5
-editor.fx.0.y=189
2
+editor.fx.0.height=0
3
+editor.fx.0.width=0
4
+editor.fx.0.x=0
5
+editor.fx.0.y=0
6 6
 objectbench.height=128
7 7
 objectbench.width=1171
8 8
 package.divider.horizontal=0.6