import javax.swing.JOptionPane; import java.text.NumberFormat; import java.util.Locale; //This example shows a combination of the decorator pattern and inheritance //It is an adaptation of an example of Bruce Eckel public class TestCoffeeShop { public static void main(String[] args) throws Exception { DrinkItem aDrink; aDrink = new Cream(new Coffee()); display(aDrink); aDrink = new Coffee(); aDrink = new Cream(aDrink); aDrink = new Sugar(aDrink); aDrink = new Lemon(aDrink); display(aDrink); aDrink = new Cream(new Tea()); aDrink = new Honey(aDrink); display(aDrink); aDrink = new Coffee(); display(aDrink); } // end main public static void display(DrinkItem d) { NumberFormat money = NumberFormat.getCurrencyInstance(Locale.US); String out = "Your drink is " + d.getDescription(); out += "\nThe cost is " + money.format(d.getCost()); JOptionPane.showMessageDialog(null,out); } } // end TestCoffeeShop