Quiz 03 sample questions

The quiz will have two questions, and cover material through the end of the List topics we’ve gotten to so far.

In the questions, you will write a short class or method according to a textual description. For example, a question might state:

Write a method public static <E> List<E> notIn(List<E> list1, List<E> list2). notIn should return a list that contains the elements present in list1 but not present in list2. The original lists must not be modified. For full credit, your method must correctly use generics, and must not contain unnecessary method calls or loops, even if they do not otherwise impact correctness. You may assume List and ArrayList are correctly imported from java.util. You may not import other classes.


Another question might state:

Write a generic class MyList<E> that extends an existing implementation of List. MyList should include a method public List<E> reversed(). reversed returns a new list consisting of the elements of the current list in reverse order. reversed must not modify the list. For full credit, your method must correctly use generic types, and must not contain unnecessary method calls or loops, even if they do not otherwise impact correctness. You may assume List and ArrayList are correctly imported from java.util. You may not import other classes.


You can check your answers here.