Lauren Green 6 лет назад
Родитель
Сommit
9171806ae2
1 измененных файлов: 54 добавлений и 8 удалений
  1. 54
    8
      src/main/java/com/zipcodewilmington/StringArrayUtils.java

+ 54
- 8
src/main/java/com/zipcodewilmington/StringArrayUtils.java Просмотреть файл

@@ -1,4 +1,5 @@
1 1
 package com.zipcodewilmington;
2
+import java.util.Arrays;
2 3
 
3 4
 /**
4 5
  * Created by leon on 1/29/18.
@@ -9,7 +10,7 @@ public class StringArrayUtils {
9 10
      * @return first element of specified array
10 11
      */ // TODO
11 12
     public static String getFirstElement(String[] array) {
12
-        return null;
13
+        return array[0];
13 14
     }
14 15
 
15 16
     /**
@@ -17,7 +18,7 @@ public class StringArrayUtils {
17 18
      * @return second element in specified array
18 19
      */
19 20
     public static String getSecondElement(String[] array) {
20
-        return null;
21
+        return array[1];
21 22
     }
22 23
 
23 24
     /**
@@ -25,7 +26,7 @@ public class StringArrayUtils {
25 26
      * @return last element in specified array
26 27
      */ // TODO
27 28
     public static String getLastElement(String[] array) {
28
-        return null;
29
+        return array[array.length - 1];
29 30
     }
30 31
 
31 32
     /**
@@ -33,7 +34,7 @@ public class StringArrayUtils {
33 34
      * @return second to last element in specified array
34 35
      */ // TODO
35 36
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
37
+        return array[array.length - 2];
37 38
     }
38 39
 
39 40
     /**
@@ -42,7 +43,17 @@ public class StringArrayUtils {
42 43
      * @return true if the array contains the specified `value`
43 44
      */ // TODO
44 45
     public static boolean contains(String[] array, String value) {
45
-        return false;
46
+
47
+        boolean result = false;
48
+
49
+        for (String s : array) {
50
+
51
+            if (s.equals(value))
52
+                result = true;
53
+
54
+        }
55
+
56
+        return result;
46 57
     }
47 58
 
48 59
     /**
@@ -50,7 +61,18 @@ public class StringArrayUtils {
50 61
      * @return an array with identical contents in reverse order
51 62
      */ // TODO
52 63
     public static String[] reverse(String[] array) {
53
-        return null;
64
+
65
+        String[] result = new String[array.length];
66
+        int j = 0;
67
+
68
+        for (int i = (array.length - 1); i >= 0; i--) {
69
+
70
+            result[j] = array[i];
71
+            j++;
72
+
73
+        }
74
+
75
+        return result;
54 76
     }
55 77
 
56 78
     /**
@@ -58,7 +80,8 @@ public class StringArrayUtils {
58 80
      * @return true if the order of the array is the same backwards and forwards
59 81
      */ // TODO
60 82
     public static boolean isPalindromic(String[] array) {
61
-        return false;
83
+
84
+        return Arrays.equals(array, StringArrayUtils.reverse(array));
62 85
     }
63 86
 
64 87
     /**
@@ -66,7 +89,30 @@ public class StringArrayUtils {
66 89
      * @return true if each letter in the alphabet has been used in the array
67 90
      */ // TODO
68 91
     public static boolean isPangramic(String[] array) {
69
-        return false;
92
+
93
+        String alpha = "abcdefghijklmnopqrstuvwxyz";
94
+        String original = Arrays.toString(array).replace(" ", "").toLowerCase();
95
+        original.replace(",", "");
96
+
97
+        char[] orig = original.toCharArray();
98
+        Arrays.sort(orig);
99
+        String ori = Arrays.toString(orig).replace(",", "").replace(" ", "").replace("[", "").replace("]", "");
100
+        String finalResult = "";
101
+
102
+        //Stopped here
103
+        for (int i = 0; i < ori.length(); i++) {
104
+            String currentLetter = "";
105
+            if(!lastLetter.equals(ori.substring(i, i+1))) {
106
+                lastLetter = ori.substring(i, i+1);
107
+                finalResult = finalResult + ori.substring(i, i+1);
108
+
109
+            }
110
+
111
+        }
112
+
113
+        System.out.println(finalResult);
114
+
115
+        return false;//finalResult.equals(alpha);
70 116
     }
71 117
 
72 118
     /**