Java Reference
In-Depth Information
55 {
56 double amountDue = 0 ;
57 for (LineItem i : items)
58 {
59 amountDue = amountDue +
i.getTotalPrice();
60 }
61 return amountDue;
62 }
63
64 private Address billingAddress;
65 private ArrayList<LineItem> items;
66 }
553
554
ch12/invoice/LineItem.java
1 /**
2 Describes a quantity of an article to purchase.
3 */
4 public class LineItem
5 {
6 /**
7 Constructs an item from the product and quantity.
8 @param aProduct the product
9 @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;
Search WWH ::




Custom Search