01: /**
02: A decorator for an item that applies a discount.
03: */
04: public class DiscountedItem implements LineItem
05: {
06: /**
07: Constructs a discounted item.
08: @param item the item to be discounted
09: @param discount the discount percentage
10: */
11: public DiscountedItem(LineItem item, double discount)
12: {
13: this.item = item;
14: this.discount = discount;
15: }
16:
17: public double getPrice()
18: {
19: return item.getPrice() * (1 - discount / 100);
20: }
21:
22: public String toString()
23: {
24: return item.toString() + " (Discount " + discount
25: + "%)";
26: }
27:
28: private LineItem item;
29: private double discount;
30: }