001package horstmann.ch05_invoice;
002/**
003   A decorator for an item that applies a discount.
004 */
005public class DiscountedItem implements LineItem
006{
007        /**
008      Constructs a discounted item.
009      @param item the item to be discounted
010      @param discount the discount percentage
011         */
012        public DiscountedItem(LineItem item, double discount)
013        {
014                this.item = item;
015                this.discount = discount;
016        }
017
018        public double getPrice()
019        {
020                return item.getPrice() * (1 - discount / 100);
021        }
022
023        public String toString()
024        {
025                return item.toString() + " (Discount " + discount
026                                + "%)";
027        }
028
029        private LineItem item;
030        private double discount;
031}