01: import java.util.*; 02: 03: /** 04: A bundle of items that is again an item. 05: */ 06: public class Bundle implements LineItem 07: { 08: /** 09: Constructs a bundle with no items. 10: */ 11: public Bundle() { items = new ArrayList(); } 12: 13: /** 14: Adds an item to the bundle. 15: @param item the item to add 16: */ 17: public void add(LineItem item) { items.add(item); } 18: 19: public double getPrice() 20: { 21: double price = 0; 22: for (int i = 0; i < items.size(); i++) 23: { 24: LineItem item = (LineItem) items.get(i); 25: price += item.getPrice(); 26: } 27: return price; 28: } 29: 30: public String toString() 31: { 32: String description = "Bundle: "; 33: for (int i = 0; i < items.size(); i++) 34: { 35: if (i > 0) description += ", "; 36: LineItem item = (LineItem) items.get(i); 37: description += item.toString(); 38: } 39: return description; 40: } 41: 42: private ArrayList items; 43: }