Finish implementing the Java or JavaScript Util methods shown below (i.e. toArray, copyOfArray, swap, flip, flipCopyOfArray, and flipCopyOfString).
When you are finished, send an email to jspurgeon@vcstudent.org with the subject "Exercise[30]". Include your completed functions in the body of the email message or include a reference to the code in the message.
Grading Rubric
Each correctly completed method is worth 10 points.
Following the instructions above is worth 10 points.
Work turned in late will be penalized 10 points.
Due Date
End of day Mon, 5 Dec 2016
Note
java FlippantFunctions "abc"
should output:
abc cba abc cba
FlippantFunctions.main(["abc"])
should output:
abc cba ["a", "b", "c"] ["c", "b", "a"]
class Util {
public static char[] toArray(String s) {
int i = s.length();
char[] array = new char[i];
return array;
}
public static char[] copyOfArray(char[] array) {
int i = array.length;
char[] copy = new char[i];
return copy;
}
public static char[] swap(char[] array, int i, int j) {
return array;
}
public static char[] flip(char[] array) {
return array;
}
public static char[] flipCopyOfArray(char[] array) {
char[] copy = Util.copyOfArray(array);
return Util.flip(copy);
}
public static String flipCopyOfString(String s) {
String f = "";
return f;
}
}
class FlippantFunctions {
public static void main(String[] args) {
String s = args[0];
String sf = Util.flipCopyOfString(s);
char[] a = Util.toArray(s);
char[] af = Util.flipCopyOfArray(a);
System.out.println(s);
System.out.println(sf);
System.out.println(a);
System.out.println(af);
}
}