Browse Source

added methods from replace to remove

mpierse 8 years ago
parent
commit
719726fba8

+ 33
- 6
src/main/java/com/zipcodewilmington/StringArrayUtils.java View File

77
      */ // TODO
77
      */ // TODO
78
     public static boolean isPalindromic(String[] array) {
78
     public static boolean isPalindromic(String[] array) {
79
 
79
 
80
-        return Arrays.equals(reverse(array), array);
80
+        return Arrays.equals(array, reverse(array));
81
     }
81
     }
82
 
82
 
83
     /**
83
     /**
84
      * @param array array of String objects
84
      * @param array array of String objects
85
      * @return true if each letter in the alphabet has been used in the array
85
      * @return true if each letter in the alphabet has been used in the array
86
-     */ // TODO
86
+     */  //TODO
87
     public static boolean isPangramic(String[] array) {
87
     public static boolean isPangramic(String[] array) {
88
-        boolean[] letterPresent = boolean[26];
89
-        if (){
88
+        String concatString = "";
89
+        String alphabet = "qwertyuiopasdfghjklzxcvbnm";
90
+        boolean panagramic = true;
91
+        for (int i=0; i<array.length; i++){
92
+            concatString += array[i];
93
+        }
94
+        char[] alphArr = alphabet.toCharArray();
95
+        for (int i=0; i<alphabet.length(); i++){
90
 
96
 
97
+            if (concatString.indexOf(alphArr[i])<0){
98
+                panagramic = false;
99
+                break;
100
+            }
91
         }
101
         }
102
+        return panagramic;
92
     }
103
     }
93
 
104
 
94
     /**
105
     /**
97
      * @return number of occurrences the specified `value` has occurred
108
      * @return number of occurrences the specified `value` has occurred
98
      */ // TODO
109
      */ // TODO
99
     public static int getNumberOfOccurrences(String[] array, String value) {
110
     public static int getNumberOfOccurrences(String[] array, String value) {
100
-        return 0;
111
+       int counter=0;
112
+        for (int i=0; i<array.length; i++) {
113
+            if (array[i].equals(value)){
114
+                counter++;
115
+            }
116
+        }
117
+        return counter;
118
+
101
     }
119
     }
102
 
120
 
103
     /**
121
     /**
106
      * @return array with identical contents excluding values of `value`
124
      * @return array with identical contents excluding values of `value`
107
      */ // TODO
125
      */ // TODO
108
     public static String[] removeValue(String[] array, String valueToRemove) {
126
     public static String[] removeValue(String[] array, String valueToRemove) {
109
-        return null;
127
+        int valueCount = getNumberOfOccurrences(array, valueToRemove);
128
+        String[] arrayMinusValue = new String[array.length-valueCount];
129
+        int counter = 0;
130
+        for(int i=0; i<array.length; i++){
131
+            if (!array[i].equals(valueToRemove)){
132
+                array[i]=arrayMinusValue[counter];
133
+                counter++;
134
+            }
135
+        }
136
+        return arrayMinusValue;
110
     }
137
     }
111
 
138
 
112
     /**
139
     /**

+ 1
- 0
src/test/java/com/zipcodewilmington/StringArrayUtilsTest.java View File

244
         String[] array = {"Is this a plaindrome?", "This is not a plaindrome", "Is this a palindrome?", "This is not a palindrome"};
244
         String[] array = {"Is this a plaindrome?", "This is not a plaindrome", "Is this a palindrome?", "This is not a palindrome"};
245
         boolean outcome = StringArrayUtils.isPalindromic(array);
245
         boolean outcome = StringArrayUtils.isPalindromic(array);
246
         Assert.assertFalse(outcome);
246
         Assert.assertFalse(outcome);
247
+        System.out.println(outcome);
247
     }
248
     }
248
 
249
 
249
 
250