浏览代码

commiting changes

Lauren Green 6 年前
父节点
当前提交
9171806ae2
共有 1 个文件被更改,包括 54 次插入8 次删除
  1. 54
    8
      src/main/java/com/zipcodewilmington/StringArrayUtils.java

+ 54
- 8
src/main/java/com/zipcodewilmington/StringArrayUtils.java 查看文件

1
 package com.zipcodewilmington;
1
 package com.zipcodewilmington;
2
+import java.util.Arrays;
2
 
3
 
3
 /**
4
 /**
4
  * Created by leon on 1/29/18.
5
  * Created by leon on 1/29/18.
9
      * @return first element of specified array
10
      * @return first element of specified array
10
      */ // TODO
11
      */ // TODO
11
     public static String getFirstElement(String[] array) {
12
     public static String getFirstElement(String[] array) {
12
-        return null;
13
+        return array[0];
13
     }
14
     }
14
 
15
 
15
     /**
16
     /**
17
      * @return second element in specified array
18
      * @return second element in specified array
18
      */
19
      */
19
     public static String getSecondElement(String[] array) {
20
     public static String getSecondElement(String[] array) {
20
-        return null;
21
+        return array[1];
21
     }
22
     }
22
 
23
 
23
     /**
24
     /**
25
      * @return last element in specified array
26
      * @return last element in specified array
26
      */ // TODO
27
      */ // TODO
27
     public static String getLastElement(String[] array) {
28
     public static String getLastElement(String[] array) {
28
-        return null;
29
+        return array[array.length - 1];
29
     }
30
     }
30
 
31
 
31
     /**
32
     /**
33
      * @return second to last element in specified array
34
      * @return second to last element in specified array
34
      */ // TODO
35
      */ // TODO
35
     public static String getSecondToLastElement(String[] array) {
36
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
37
+        return array[array.length - 2];
37
     }
38
     }
38
 
39
 
39
     /**
40
     /**
42
      * @return true if the array contains the specified `value`
43
      * @return true if the array contains the specified `value`
43
      */ // TODO
44
      */ // TODO
44
     public static boolean contains(String[] array, String value) {
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
      * @return an array with identical contents in reverse order
61
      * @return an array with identical contents in reverse order
51
      */ // TODO
62
      */ // TODO
52
     public static String[] reverse(String[] array) {
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
      * @return true if the order of the array is the same backwards and forwards
80
      * @return true if the order of the array is the same backwards and forwards
59
      */ // TODO
81
      */ // TODO
60
     public static boolean isPalindromic(String[] array) {
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
      * @return true if each letter in the alphabet has been used in the array
89
      * @return true if each letter in the alphabet has been used in the array
67
      */ // TODO
90
      */ // TODO
68
     public static boolean isPangramic(String[] array) {
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
     /**