import java.util.ArrayList; class Box extends Item { private String type; private ArrayList contents; private int emptyWeight; public Box(String type) { this.type = type; if (type.equals("wooden")) { this.emptyWeight = 10; } else { this.emptyWeight = 1; } contents = new ArrayList(); } public int getWeight() { int total = this.emptyWeight; for (Item thing : contents) { total += thing.getWeight(); } return total; } public void pack(Item x) { contents.add(x); } public boolean isPerishable() { for (Item thing : contents) { if (thing.isPerishable()) { return true; } } return false; } public String toString() { String p = ""; if (isPerishable()) { p = " perishable"; } return "A " + contents.size() + "-item " + type + p + " box"; } }