public class ArrayShifter { //instance variables: int theArray[]; public ArrayShifter (int [] iArray){ //conrtuctor, sets the values for theArray this.theArray = iArray; } public int [] shiftLeft(int value){ //returns an array where the elements of theArray have been shifted the left //The value passed in becomes the rightmost element //Thus the leftmost element of theArray will not be in the returned array. //example: initital array is {1, 2, 3, 4}, and 8 is passed in // then the array {2, 3, 4, 8} is returned (this.theArray does not change) int [] newArray = new int[this.theArray.length]; for (int i = 1; i < this.theArray.length; i++){ newArray[i-1] = this.theArray[i]; } newArray[this.theArray.length - 1] = value; return newArray; } public int [] shiftRight(int value){ //returns an array where the elements of theArray have been shifted the right //The value passed in becomes the leftmost element. //Thus the rightmost element of theArray will not be in the returned array. //example: initital array is {1, 2, 3, 4}, and 8 is passed in // then the array {8, 1, 2, 3} is returned (theArray does not change) int [] newArray = new int[this.theArray.length]; for (int i = 0; i < this.theArray.length - 1; i++){ newArray[i+1] = this.theArray[i]; } newArray[0] = value; return newArray; } public static void main(String [] args){ //just tests the methods above int [] iArray = {1, 2, 3, 4}; ArrayShifter ar = new ArrayShifter(iArray); int [] array2 = ar.shiftLeft(8); for (int x: array2) System.out.println(x); array2 = ar.shiftRight(8); for (int x: array2) System.out.println(x); //note: the values for theArray do not change, they are just used with the shift methods } }