import java.util.*; // a - introduce , and and T all over. // I did not need to change anything in the body of any // of the methods. public class Store{ private List goods; public Store() { goods = new ArrayList(); } public void add(T good){ goods.add(good); } public T remove(){ return goods.remove(goods.size()-1); } // 3.c // The things we want to add to the store are // all subclasses of T. But we need to use // the wildcard to be able to pass a collection // as parameter. This is ok, since we just want // to read the elements from the collection, // not to change the collection public void addAll(Collection c){ for(T elm:c) goods.add(elm); } // 3.d // Here we need a collection which we can copy // all our elements into. Any collection which // can contain our type T - or something more // general - can contain our stuff. public void sellAll(Collection buyer){ for(T elm:goods) buyer.add(elm); } }