Przeglądaj źródła

Finished String Utilities

shakila 6 lat temu
rodzic
commit
372afc07fa
3 zmienionych plików z 27 dodań i 21 usunięć
  1. 1
    0
      PredicateUtilities.java
  2. 18
    13
      StringUtilities.java
  3. 8
    8
      package.bluej

+ 1
- 0
PredicateUtilities.java Wyświetl plik

@@ -10,6 +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
+       
13 14
        return null;
14 15
    }
15 16
 

+ 18
- 13
StringUtilities.java Wyświetl plik

@@ -1,5 +1,4 @@
1 1
 
2
-
3 2
 /**
4 3
  * Created by dan on 6/14/17.
5 4
  */
@@ -8,7 +7,7 @@ public class StringUtilities {
8 7
      * @return `Hello World` as a string
9 8
      */
10 9
     public 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 String concatenation(String firstSegment, String secondSegment){
20
-        return null;
19
+        return String.join("",firstSegment,secondSegment);
21 20
     }
22 21
 
23 22
     /**
@@ -26,7 +25,8 @@ public class StringUtilities {
26 25
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 26
      */
28 27
     public String concatenation(int firstSegment, String secondSegment){
29
-        return null;
28
+        Integer.toString(firstSegment);
29
+        return firstSegment + secondSegment;
30 30
     }
31 31
 
32 32
     /**
@@ -34,7 +34,7 @@ public class StringUtilities {
34 34
      * @return the first 3 characters of `input`
35 35
      */
36 36
     public String getPrefix(String input){
37
-        return null;
37
+        return input.substring(0,3);
38 38
     }
39 39
 
40 40
     /**
@@ -42,7 +42,7 @@ public class StringUtilities {
42 42
      * @return the last 3 characters of `input`
43 43
      */
44 44
     public String getSuffix(String input){
45
-        return null;
45
+        return input.substring(input.length()-3);
46 46
     }
47 47
 
48 48
     /**
@@ -51,7 +51,11 @@ public class StringUtilities {
51 51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 52
      */
53 53
     public Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
54
+        if (inputValue.equals(comparableValue)) {
55
+            return true;
56
+        } else {
57
+            return false;
58
+        }
55 59
     }
56 60
 
57 61
     /**
@@ -59,15 +63,16 @@ public class StringUtilities {
59 63
      * @return the middle character of `inputValue`
60 64
      */
61 65
     public Character getMiddleCharacter(String inputValue){
62
-        return null;
63
-    }
64 66
 
67
+        return inputValue.charAt(((inputValue.length()-1)/2));
68
+
69
+    }
65 70
     /**
66 71
      * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67 72
      * @return the first sequence of characters
68 73
      */
69 74
     public String getFirstWord(String spaceDelimitedString){
70
-        return null;
75
+        return spaceDelimitedString.split(" ")[0];
71 76
     }
72 77
 
73 78
     /**
@@ -75,7 +80,7 @@ public class StringUtilities {
75 80
      * @return the second word of a string delimited by spaces.
76 81
      */
77 82
     public String getSecondWord(String spaceDelimitedString){
78
-        return null;
83
+        return spaceDelimitedString.split(" ")[1];
79 84
     }
80 85
 
81 86
     /**
@@ -91,7 +96,7 @@ public class StringUtilities {
91 96
      * @return an identical string with spaces removed.
92 97
      */
93 98
     public String removeWhitespace(String input){
94
-        return null;
99
+        return input.replaceAll(" ","");
95 100
     }
96 101
 
97 102
     /**
@@ -99,6 +104,6 @@ public class StringUtilities {
99 104
      * @return an identical string with spaces in the front and end removed.
100 105
      */
101 106
     public String trim(String input){
102
-        return null;
107
+        return input.trim();
103 108
     }
104 109
 }

+ 8
- 8
package.bluej Wyświetl plik

@@ -2,16 +2,16 @@
2 2
 dependency1.from=StringUtilitiesTest
3 3
 dependency1.to=StringUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=PredicateUtilitiesTest
6
-dependency2.to=PredicateUtilities
5
+dependency2.from=MathUtilitiesTest
6
+dependency2.to=MathUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=MathUtilitiesTest
9
-dependency3.to=MathUtilities
8
+dependency3.from=PredicateUtilitiesTest
9
+dependency3.to=PredicateUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=0
12
-editor.fx.0.width=0
13
-editor.fx.0.x=0
14
-editor.fx.0.y=0
11
+editor.fx.0.height=709
12
+editor.fx.0.width=995
13
+editor.fx.0.x=240
14
+editor.fx.0.y=23
15 15
 objectbench.height=145
16 16
 objectbench.width=776
17 17
 package.divider.horizontal=0.6