001package horstmann.ch05_invoice;
002import java.util.ArrayList;
003
004/**
005   A bundle of line items that is again a line item.
006 */
007public class Bundle implements LineItem
008{
009        /**
010      Constructs a bundle with no items.
011         */
012        public Bundle() { items = new ArrayList<LineItem>(); }
013
014        /**
015      Adds an item to the bundle.
016      @param item the item to add
017         */
018        public void add(LineItem item) { items.add(item); }
019
020        public double getPrice()
021        {
022                double price = 0;
023
024                for (LineItem item : items)
025                        price += item.getPrice();
026                return price;
027        }
028
029        public String toString()
030        {
031                String description = "Bundle: ";
032                for (int i = 0; i < items.size(); i++)
033                {
034                        if (i > 0) description += ", ";
035                        description += items.get(i).toString();
036                }
037                return description;
038        }
039
040        private ArrayList<LineItem> items;
041}