The exercise week 5, we will work with the following tasks.
public static void shiftLeft1(int[] a)which shifts the array a with one step to the left.
public static int[] shiftLeft2(int[] a)which also shifts a one step to the left but it does not change the argument itself. Instead it creates and returns a new array which is the result of the operation.
public interface Result { public String getPlayer(); public int getScore(); }
In addition to the constructor, the class offers the following methods:
Hint: Use an array of results and an integer variable that keeps how much of the array is filled in. Constructors and all methods except add should then be easy to define.
The add is a lot trickier. A few tips: Hold the results sorted in the array. Upon insertion of a new result (in add), check first if the array is full and if so, which elements do not fit. Start searching from the bottom of the array until the right place for the new result is found.
Note that we do not have much to gain by using a list from the Java Collections Framework, since add is so special. Using an array and an integer that specifies the number of elements currently in the list is probably just as simple.