donnaj преди 8 години
родител
ревизия
8507d72654
променени са 2 файла, в които са добавени 93 реда и са изтрити 13 реда
  1. 51
    13
      StringArrayUtils.java
  2. 42
    0
      package.bluej

+ 51
- 13
StringArrayUtils.java Целия файл

@@ -9,7 +9,7 @@ public class StringArrayUtils {
9 9
      * @return first element of specified array
10 10
      */ // TODO
11 11
     public static String getFirstElement(String[] array) {
12
-        return null;
12
+        return array[0];
13 13
     }
14 14
 
15 15
     /**
@@ -17,7 +17,7 @@ public class StringArrayUtils {
17 17
      * @return second element in specified array
18 18
      */
19 19
     public static String getSecondElement(String[] array) {
20
-        return null;
20
+        return array[1];
21 21
     }
22 22
 
23 23
     /**
@@ -25,7 +25,7 @@ public class StringArrayUtils {
25 25
      * @return last element in specified array
26 26
      */ // TODO
27 27
     public static String getLastElement(String[] array) {
28
-        return null;
28
+        return array[array.length-1];
29 29
     }
30 30
 
31 31
     /**
@@ -33,7 +33,7 @@ public class StringArrayUtils {
33 33
      * @return second to last element in specified array
34 34
      */ // TODO
35 35
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
36
+        return array[array.length-2];
37 37
     }
38 38
 
39 39
     /**
@@ -42,15 +42,22 @@ public class StringArrayUtils {
42 42
      * @return true if the array contains the specified `value`
43 43
      */ // TODO
44 44
     public static boolean contains(String[] array, String value) {
45
+        for(int i = 0; i < array.length; i++) {
46
+            if(array[i].equals(value)) return true;
47
+        }
45 48
         return false;
46 49
     }
47
-
50
+    
48 51
     /**
49 52
      * @param array of String objects
50 53
      * @return an array with identical contents in reverse order
51 54
      */ // TODO
52 55
     public static String[] reverse(String[] array) {
53
-        return null;
56
+        String[] revArray = new String[array.length];
57
+        for (int i = 0; i < array.length; i++) {
58
+            revArray[i] = array[array.length - 1 - i];
59
+        }
60
+        return revArray;
54 61
     }
55 62
 
56 63
     /**
@@ -58,15 +65,27 @@ public class StringArrayUtils {
58 65
      * @return true if the order of the array is the same backwards and forwards
59 66
      */ // TODO
60 67
     public static boolean isPalindromic(String[] array) {
61
-        return false;
68
+        
69
+    for ( int i = 0; i < array.length / 2; i++) {
70
+        if (array[i] != array[array.length - 1 - i]) {
71
+          return false;
72
+        }
73
+    }    
74
+    return true;
62 75
     }
63
-
76
+    
64 77
     /**
65 78
      * @param array array of String objects
66 79
      * @return true if each letter in the alphabet has been used in the array
67 80
      */ // TODO
68 81
     public static boolean isPangramic(String[] array) {
69
-        return false;
82
+        for(char c = 'a';c <= 'z'; ++c) {
83
+            if(array.toString().contains(String.valueOf(c))) {
84
+                return true;
85
+        
86
+    }
87
+        
88
+    }return false;
70 89
     }
71 90
 
72 91
     /**
@@ -74,17 +93,36 @@ public class StringArrayUtils {
74 93
      * @param value value to check array for
75 94
      * @return number of occurrences the specified `value` has occurred
76 95
      */ // TODO
96
+    
77 97
     public static int getNumberOfOccurrences(String[] array, String value) {
78
-        return 0;
79
-    }
98
+        int num = 0;
99
+        for (int i=0;i<array.length;i++){
100
+            if (array[i]== value){
101
+                num++;
102
+            }
103
+
104
+        }
80 105
 
106
+        return num;
107
+    }
108
+    
81 109
     /**
82 110
      * @param array         array of String objects
83 111
      * @param valueToRemove value to remove from array
84 112
      * @return array with identical contents excluding values of `value`
85 113
      */ // TODO
86 114
     public static String[] removeValue(String[] array, String valueToRemove) {
87
-        return null;
115
+        String[] arr = new String[array.length-1];
116
+        String[] remArr = new String[1];
117
+        for (int i=0;i<array.length;i++){
118
+            if (array[i]!=valueToRemove){
119
+                arr[i] = array[i];
120
+
121
+            }else { remArr[i] += array[i];}
122
+
123
+        }
124
+
125
+        return arr;
88 126
     }
89 127
 
90 128
     /**
@@ -94,7 +132,7 @@ public class StringArrayUtils {
94 132
     public static String[] removeConsecutiveDuplicates(String[] array) {
95 133
         return null;
96 134
     }
97
-
135
+    
98 136
     /**
99 137
      * @param array array of chars
100 138
      * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings

+ 42
- 0
package.bluej Целия файл

@@ -0,0 +1,42 @@
1
+#BlueJ package file
2
+dependency1.from=StringArrayUtilsTest
3
+dependency1.to=StringArrayUtils
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=722
6
+editor.fx.0.width=800
7
+editor.fx.0.x=240
8
+editor.fx.0.y=23
9
+objectbench.height=101
10
+objectbench.width=461
11
+package.divider.horizontal=0.6
12
+package.divider.vertical=0.8007380073800738
13
+package.editor.height=427
14
+package.editor.width=674
15
+package.editor.x=91
16
+package.editor.y=68
17
+package.frame.height=600
18
+package.frame.width=800
19
+package.numDependencies=1
20
+package.numTargets=2
21
+package.showExtends=true
22
+package.showUses=true
23
+project.charset=UTF-8
24
+readme.height=58
25
+readme.name=@README
26
+readme.width=47
27
+readme.x=10
28
+readme.y=10
29
+target1.height=50
30
+target1.name=StringArrayUtilsTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=150
34
+target1.x=130
35
+target1.y=10
36
+target2.height=50
37
+target2.name=StringArrayUtils
38
+target2.showInterface=false
39
+target2.type=ClassTarget
40
+target2.width=120
41
+target2.x=70
42
+target2.y=70