The microlabs for the Generics chapter are all grouped together. So, you need to work through them package by package. The following list is the package name followed by a quick description of the assignment.
- StackArrayList -- Implement
Stack<E>to use an ArrayList as a stack. You need to make thepush,pop, andisEmptyfunctions. - StackArray -- Implement
Stack<E>to use an array as a stack. You'll need to potentially grow the array in thepushmethod. Do this first with anE[]array, and then again with anObject[]array. Both should compile without warnings and pass the tests. - Table -- Implemented for you is Entry<K, V>.
Implement Table<K,V> so that it manages an ArrayList of Entry<K,V>. You must implementgetwhich takes a key and returns either the entry from the ArrayList with that key, or null if none is found.putwhich takes a key and value and sets the value in the ArrayList to Entry(key, value);- Remember, a key point to exactly one value
removewhich takes a key and removes it from the ArrayList if it's in there. It's a void method; no return type.
- TableNested -- Take the previous microlab, and make Entry a nested class. Think about if it'll need to be generic or not.
- Swap -- Get the test to pass. Look at the specific values being passed in to help you figure it out. Modify the tests, not the code.
- ArrayListCombiner -- Write two methods,
superCombinerandextendCombiner, which each take two arraylists and append all of the items from the second to the first.superCombinershould use? super EandextendCombinershould use? extends E. - MapFunc -- Make a
mapmethod that takes an ArrayList and aFunction<T,R>object and returns an arraylist containing all of the elements of the first with the function applied to them. - Pair -- This is a multi-step one:
- Create a Pair that stores a pair of elements of type
E. - Create two methods,
minandmax, that return the largest and smallest of thePair. - Create a utility class called
Arraysand, in that, create a methodpublic static <___> Pair<E> firstLast(ArrayList<___> a)
That returns a Pair containing the first and last element of the array.
NOTE: The<___>is there because you need to fill in the blank. - In
Arraysmake two methods,minandmaxthat returns the smallest and largest elements in the ArrayList. - In
Arraysmake aminMaxfunction that returns aPairwith the minimum and maximum values of the ArrayList.
- Create a Pair that stores a pair of elements of type