Bladeren bron

Completed lab

Rachelle 6 jaren geleden
bovenliggende
commit
82c6e9db7d
4 gewijzigde bestanden met toevoegingen van 275 en 278 verwijderingen
  1. 230
    233
      MathUtilities.java
  2. 34
    35
      PredicateUtilities.java
  3. 10
    9
      StringUtilities.java
  4. 1
    1
      package.bluej

+ 230
- 233
MathUtilities.java Bestand weergeven

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

+ 34
- 35
PredicateUtilities.java Bestand weergeven

@@ -1,42 +1,41 @@
1 1
 
2
-
3 2
 /**
4
-* Created by dan on 6/14/17.
5
-*/
3
+ * Created by dan on 6/14/17.
4
+ */
6 5
 public class PredicateUtilities {
7
-   /**
8
-    * @param x
9
-    * @param y
10
-    * @return true if `x` is greater than `y`
11
-    */
12
-   public Boolean isGreaterThan(int x, int y) {
13
-       return (x>y);
14
-   }
6
+    /**
7
+     * @param x
8
+     * @param y
9
+     * @return true if `x` is greater than `y`
10
+     */
11
+    public Boolean isGreaterThan(int x, int y) {
12
+        return (x>y);
13
+    }
15 14
 
16
-   /**
17
-    * @param x
18
-    * @param y
19
-    * @return true if `x` is less than `y`
20
-    */
21
-   public Boolean isLessThan(int x, int y) {
22
-       return (x<y);
23
-   }
15
+    /**
16
+     * @param x
17
+     * @param y
18
+     * @return true if `x` is less than `y`
19
+     */
20
+    public Boolean isLessThan(int x, int y) {
21
+        return (x<y);
22
+    }
24 23
 
25
-   /**
26
-    * @param x
27
-    * @param y
28
-    * @return true if `x` is greater than or equal to `y`
29
-    */
30
-   public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-       return (x>=y);
32
-   }
24
+    /**
25
+     * @param x
26
+     * @param y
27
+     * @return true if `x` is greater than or equal to `y`
28
+     */
29
+    public Boolean isGreaterThanOrEqualTo(int x, int y) {
30
+        return (x>=y);
31
+    }
33 32
 
34
-   /**
35
-    * @param x
36
-    * @param y
37
-    * @return true if `x` is less than or equal to `y`
38
-    */
39
-   public Boolean isLessThanOrEqualTo(int x, int y) {
40
-       return (x<=y);
41
-   }
33
+    /**
34
+     * @param x
35
+     * @param y
36
+     * @return true if `x` is less than or equal to `y`
37
+     */
38
+    public Boolean isLessThanOrEqualTo(int x, int y) {
39
+        return (x<=y);
40
+    }
42 41
 }

+ 10
- 9
StringUtilities.java Bestand weergeven

@@ -1,5 +1,4 @@
1
-
2
-
1
+import java.util.*;
3 2
 /**
4 3
  * Created by dan on 6/14/17.
5 4
  */
@@ -61,16 +60,17 @@ public class StringUtilities {
61 60
     public Character getMiddleCharacter(String inputValue){
62 61
         if ((inputValue.length() % 2) == 1 ){
63 62
             return inputValue.charAt(inputValue.length()/2);
64
-    }else{
63
+        }else{
65 64
             return inputValue.charAt((inputValue.length()-1)/2);
66
-    }
67
-}   
65
+        }
66
+    }   
68 67
 
69 68
     /**
70 69
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
71 70
      * @return the first sequence of characters
72 71
      */
73 72
     public String getFirstWord(String spaceDelimitedString){
73
+        //indexOf searches for the first instance of something
74 74
         int firstSpace = spaceDelimitedString.indexOf(" ");
75 75
         return spaceDelimitedString.substring(0,firstSpace);
76 76
     }
@@ -80,9 +80,10 @@ public class StringUtilities {
80 80
      * @return the second word of a string delimited by spaces.
81 81
      */
82 82
     public String getSecondWord(String spaceDelimitedString){
83
-        int firstSpace = spaceDelimitedString.indexOf(" ");
84
-        String removedFirstWord = spaceDelimitedString.substring(firstSpace);
85
-        return removedFirstWord.substring(1);
83
+        //scanner.next searches for the next word
84
+        Scanner scanner = new Scanner(spaceDelimitedString);
85
+        scanner.next();
86
+        return scanner.next();
86 87
     }
87 88
 
88 89
     /**
@@ -92,7 +93,7 @@ public class StringUtilities {
92 93
     public String reverse(String stringToReverse){
93 94
         String newString = "";
94 95
         for (int x = stringToReverse.length()-1; x >= 0; x--){
95
-        newString += stringToReverse.charAt(x);
96
+            newString += stringToReverse.charAt(x);
96 97
         }
97 98
         return newString;
98 99
     }

+ 1
- 1
package.bluej Bestand weergeven

@@ -13,7 +13,7 @@ editor.fx.0.width=800
13 13
 editor.fx.0.x=429
14 14
 editor.fx.0.y=23
15 15
 objectbench.height=145
16
-objectbench.width=776
16
+objectbench.width=461
17 17
 package.divider.horizontal=0.6
18 18
 package.divider.vertical=0.7195571955719557
19 19
 package.editor.height=383