Array List Reverse and Rotation Lab-11 George Mensom University with passed test cases

Fill in the definitions to two ArrayList utility methods in the ALUtils class which is outlined below and included in the code pack for this lab. The methods are described in more detail below.import java.util.ArrayList;
public class ALUtils{
// Creates a copy of the parameter a. Reverses the order of elements
// in the copy and returns the reversed copy. Assumes a is non-null.
public static <T ArrayList<T reverse(ArrayList<T a){
// Your definition here


// Creates a copy of the given ArrayList a and rotates the copy to
// the right by the given shift. Elements at high indicies wrap
// around to lower indices. Assumes parameter a is non-null and
// that shift is a non-negative number. Returns the rotated copy.
public static <T ArrayList<T rotate(ArrayList<T a, int shift){
// Your definition here

}In ALUtils, write a method reverse(aL) that takes any type of ArrayList and creates a reversed copy of it which is returned. The nature of this method is shown in the below demo and should produce the results indicated. You may assume that the parameter aL is non-null.public static void demo_reverse(){
ArrayList<String sa = new ArrayList<String();
String [] strings = {"A","B","C","D","E"};

// Use the a for-each to add all strings
for(String s : strings){ sa.add(s); }
// sa == [A, B, C, D, E]

ArrayList<String sb = ALUtils.reverse(sa);
// [E, D, C, B, A]
// [A, B, C, D, E] - sa is not changed

ArrayList<Integer ia = new ArrayList<Integer();
Integer [] ints = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

// Use the addAll() method add all ints from a list
// ia == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

ArrayList<Integer ib = ALUtils.reverse(ia);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] - sa not changed
}In write a static method rotate(aL, shift) which accepts any kind of ArrayList and creates a rotated copy of it. Rotation means to shift all elements forward in the list to a new position based on the integer parameter shift. If the elements would shift off the end of the list, they wrap around to the beginning. The concept should be familiar based on projects and is best illustrated by examples given below.aL = [ A, B, C, D, E, F] bL = [ A, B, C, D, E, F, G]
cL = rotate(aL, 2) cL = rotate(bL, 7)
cL== [ E, F, A, B, C, D] cL== [ A, B, C, D, E, F, G]

cL = rotate(aL, 7) cL = rotate(bL, 4)
cL== [ F, A, B, C, D, E] cL== [ D, E, F, G, A, B, C]
Powered by