public class Bundle implements LineItem
1: import java.util.*;
3: /**
4: A bundle of line items that is again a line item.
5: */
6: public class Bundle implements LineItem
7: {
8: /**
9: Constructs a bundle with no items.
10: */
11: public Bundle() { items = new ArrayList<LineItem>(); }
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); }
19: public double getPrice()
20: {
21: double price = 0;
23: for (LineItem item : items)
24: price += item.getPrice();
25: return price;
26: }
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: }
39: private ArrayList<LineItem> items;
40: }