// package base; import java.util.*; abstract class Item { String name; public abstract int check(); } class Container extends Item { Vector contents; int capacity; public static Container make( String n,int c) { Container res = new Container(); res.name = n; res.capacity=c; res.contents = new Vector(); return res; } public void addItem(Item i) { /*\label{line:cont-addItem}*/ contents.add(i); } public int check() { /*\label{line:cont-check}*/ System.out.println(" checking a new container recursively: only called if weight changed "); Iterator it=contents.iterator(); int total = 0; while(it.hasNext()) { Item child = (Item)it.next(); total+=child.check(); } System.out.println( "Container "+name+ " weighs "+total); if(total>capacity){ System.out.println( "Container "+name+ " overloaded"); } return total; } }