Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.TXT
Empty file.
91 changes: 80 additions & 11 deletions StringArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,53 @@ public class StringArrayUtils {
* @return first element of specified array
*/ // TODO
public static String getFirstElement(String[] array) {
return null;
if (array.length > 0){
return array[0];
}
else{
return null;
}


}

/**
* @param array array of String objects
* @return second element in specified array
*/
public static String getSecondElement(String[] array) {
return null;
if (array.length > 0){
return array[1];
}
else{
return null;
}
}

/**
* @param array array of String objects
* @return last element in specified array
*/ // TODO
public static String getLastElement(String[] array) {
return null;
if (array.length > 0){
return array[array.length-1];
}
else{
return null;
}
}

/**
* @param array array of String objects
* @return second to last element in specified array
*/ // TODO
public static String getSecondToLastElement(String[] array) {
return null;
if (array.length > 0){
return array[array.length-2];
}
else{
return null;
}
}

/**
Expand All @@ -42,6 +64,9 @@ public static String getSecondToLastElement(String[] array) {
* @return true if the array contains the specified `value`
*/ // TODO
public static boolean contains(String[] array, String value) {
for(String item : array){
if (value == item){return true;}
}
return false;
}

Expand All @@ -50,23 +75,55 @@ 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[] res = new String[array.length];
for(int i = 0; i < array.length; i++){
res[array.length-1-i] = array[i];
}
return res;
}

/**
* @param array array of String objects
* @return true if the order of the array is the same backwards and forwards
*/ // TODO
public static boolean isPalindromic(String[] array) {
return false;
int i = 0;
int j = array.length-1;
while( i < j){
if (array[i] != array[j]){
return false;
}
i++;
j--;
}
return true;
}

/**
* @param array array of String objects
* @return true if each letter in the alphabet has been used in the array
*/ // TODO
public static boolean isPangramic(String[] array) {
return false;
boolean[] checked = new boolean[26];
for(String item : array){
int strLen = item.length();
for(int i = 0; i < strLen; i++){
char a = item.charAt(i);
if(a >= 'A' && a <= 'Z'){
checked[a-'A'] = true;
}
else if (a >= 'a' && a <= 'z'){
checked[a-'a'] = true;
}
}
}

for(int i = 0; i < 26; i++){
if(checked[i] == false){
return false;
}
}
return true;
}

/**
Expand All @@ -75,16 +132,30 @@ 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 res = 0;
for(String str : array){
if(str == value){
res++;
}
}
return res;
}

/**
* @param array array of String objects
* @param valueToRemove value to remove from array
* @return array with identical contents excluding values of `value`
*/ // TODO

public static String[] removeValue(String[] array, String valueToRemove) {
return null;
String[] res = new String[array.length-1];
int i = 0;
for(String str : array){
if(str != valueToRemove){
res[i++] = str;
}
}
return res;
}

/**
Expand All @@ -102,6 +173,4 @@ public static String[] removeConsecutiveDuplicates(String[] array) {
public static String[] packConsecutiveDuplicates(String[] array) {
return null;
}


}
46 changes: 23 additions & 23 deletions package.bluej
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#BlueJ package file
dependency1.from=GetFirstElementTest
dependency1.from=ReverseTest
dependency1.to=StringArrayUtils
dependency1.type=UsesDependency
dependency10.from=RemoveConsecutiveDuplicatesTest
dependency10.from=IsPalindromicTest
dependency10.to=StringArrayUtils
dependency10.type=UsesDependency
dependency11.from=IsPalindromicTest
dependency11.from=GetSecondElementTest
dependency11.to=StringArrayUtils
dependency11.type=UsesDependency
dependency12.from=GetSecondElementTest
dependency12.from=ContainsTest
dependency12.to=StringArrayUtils
dependency12.type=UsesDependency
dependency13.from=ContainsTest
dependency13.from=RemoveValueTest
dependency13.to=StringArrayUtils
dependency13.type=UsesDependency
dependency2.from=ReverseTest
dependency2.from=StringArrayUtilsTest
dependency2.to=StringArrayUtils
dependency2.type=UsesDependency
dependency3.from=StringArrayUtilsTest
dependency3.from=GetFirstElementTest
dependency3.to=StringArrayUtils
dependency3.type=UsesDependency
dependency4.from=GetNumberOfOccurrencesTest
Expand All @@ -32,26 +32,26 @@ dependency6.type=UsesDependency
dependency7.from=RemovePackDuplicatesTest
dependency7.to=StringArrayUtils
dependency7.type=UsesDependency
dependency8.from=RemoveValueTest
dependency8.from=IsPangramicTest
dependency8.to=StringArrayUtils
dependency8.type=UsesDependency
dependency9.from=IsPangramicTest
dependency9.from=RemoveConsecutiveDuplicatesTest
dependency9.to=StringArrayUtils
dependency9.type=UsesDependency
editor.fx.0.height=704
editor.fx.0.width=800
editor.fx.0.x=224
editor.fx.0.y=155
objectbench.height=107
objectbench.width=837
editor.fx.0.width=771
editor.fx.0.x=-1336
editor.fx.0.y=24
objectbench.height=221
objectbench.width=976
package.divider.horizontal=0.6397146254458977
package.divider.vertical=0.8235294117647058
package.editor.height=509
package.editor.width=727
package.editor.x=77
package.editor.y=158
package.divider.vertical=0.6470588235294118
package.editor.height=411
package.editor.width=866
package.editor.x=82
package.editor.y=31
package.frame.height=704
package.frame.width=861
package.frame.width=1000
package.numDependencies=13
package.numTargets=14
package.showExtends=true
Expand Down Expand Up @@ -117,7 +117,7 @@ target3.showInterface=false
target3.type=UnitTestTargetJunit4
target3.width=140
target3.x=10
target3.y=180
target3.y=590
target4.height=50
target4.name=GetNumberOfOccurrencesTest
target4.showInterface=false
Expand All @@ -130,8 +130,8 @@ target5.name=GetSecondToLastElement
target5.showInterface=false
target5.type=UnitTestTargetJunit4
target5.width=170
target5.x=20
target5.y=450
target5.x=10
target5.y=170
target6.height=50
target6.name=GetLastElementTest
target6.showInterface=false
Expand Down