01: import java.util.*;
02: 
03: /**
04:    A bundle of line items that is again a line item.
05: */
06: public class Bundle implements LineItem
07: {
08:    /**
09:       Constructs a bundle with no items.
10:    */
11:    public Bundle() { items = new ArrayList<LineItem>(); }
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: 
23:       for (LineItem item : items)
24:          price += item.getPrice();
25:       return price;
26:    }
27: 
28:    public String toString()
29:    {
30:       String description = "Bundle: ";
31:       for (int i = 0; i < items.size(); i++)
32:       {
33:          if (i > 0) description += ", ";
34:          description += items.get(i).toString();
35:       }
36:       return description;
37:    }
38: 
39:    private ArrayList<LineItem> items;
40: }