01: /**
02:    Describes a quantity an article to purchase.
03: */
04: public class LineItem
05: {  
06:    /**
07:       Constructs an item from the product and quantity.
08:       @param aProduct the product
09:       @param aQuantity the item quantity
10:    */
11:    public LineItem(Product aProduct, int aQuantity)
12:    {  
13:       theProduct = aProduct;
14:       quantity = aQuantity;
15:    }
16:    
17:    /**
18:       Computes the total cost of this line item.
19:       @return the total price
20:    */
21:    public double getTotalPrice()
22:    {  
23:       return theProduct.getPrice() * quantity;
24:    }
25:    
26:    /**
27:       Formats this item.
28:       @return a formatted string of this item
29:    */
30:    public String format()
31:    {  
32:       return String.format("%-30s%8.2f%5d%8.2f", 
33:             theProduct.getDescription(), theProduct.getPrice(), 
34:             quantity, getTotalPrice());
35:    }
36: 
37:    private int quantity;
38:    private Product theProduct;
39: }