diff --git a/pom.xml b/pom.xml index d10c35e..4d4515a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.zipcodewilmington.labs arrayutils 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + junit diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 4bcce66..fc6d8f0 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,5 +1,7 @@ package com.zipcodewilmington; +import java.util.Arrays; + /** * Created by leon on 1/29/18. */ @@ -9,6 +11,7 @@ public class StringArrayUtils { * @return first element of specified array */ // TODO public static String getFirstElement(String[] array) { + return array[0]; } @@ -25,7 +28,8 @@ public static String getSecondElement(String[] array) { * @return last element in specified array */ // TODO public static String getLastElement(String[] array) { - return null; + + return array[array.length-1]; } /** @@ -33,7 +37,8 @@ public static String getLastElement(String[] array) { * @return second to last element in specified array */ // TODO public static String getSecondToLastElement(String[] array) { - return null; + + return array[array.length-2]; } /** @@ -42,7 +47,12 @@ public static String getSecondToLastElement(String[] array) { * @return true if the array contains the specified `value` */ // TODO public static boolean contains(String[] array, String value) { - return false; + boolean result = false; + for (int i = 0; i < array.length; i++){ + if (array[i].equals(value)) { + result = true; + } + } return result; } /** @@ -50,7 +60,12 @@ public static boolean contains(String[] array, String value) { * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - return null; + String[] reverseArray = new String[array.length]; + int j = array.length; + for (int i = 0; i < array.length; i++) { + reverseArray[j - 1] = array[i]; + j = j - 1; + } return reverseArray; } /** @@ -58,7 +73,17 @@ public static String[] reverse(String[] array) { * @return true if the order of the array is the same backwards and forwards */ // TODO public static boolean isPalindromic(String[] array) { - return false; + boolean palCheck = false; + String[] revArray = new String[array.length]; + int j = array.length; + for (int i = 0; i < array.length; i++) { + revArray[j - 1] = array[i]; + j = j - 1; + if(array[i] == revArray[i]) { + palCheck = true; + } + } + return palCheck; } /** @@ -66,7 +91,23 @@ public static boolean isPalindromic(String[] array) { * @return true if each letter in the alphabet has been used in the array */ // TODO public static boolean isPangramic(String[] array) { - return false; + boolean tester = false; + String arrayToString = ""; + for (int j= 0; j < array.length; j++) { + arrayToString = arrayToString.concat(array[j]); + } + arrayToString = arrayToString.toLowerCase(); + for(char letters = 'a';letters <= 'z'; letters++) { + for (int i = 0; i < arrayToString.length(); i ++ ){ + if (letters == arrayToString.charAt(i)) { + tester = true; + } + } + if (tester == false) { + return tester; + } tester = false; + } + return true; } /** @@ -75,7 +116,13 @@ public static boolean isPangramic(String[] array) { * @return number of occurrences the specified `value` has occurred */ // TODO public static int getNumberOfOccurrences(String[] array, String value) { - return 0; + int counter = 0; + for (int i = 0; i < array.length; i++){ + if (array[i] == value){ + counter++; + } + } + return counter; } /**