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