Java Reference
In-Depth Information
21 @param quantity
the quantity of the product
22 */
23
public void
add(Product aProduct, int
quantity)
24 {
25 LineItem anItem =
new
LineItem(aProduct, quantity);
26 items.add(anItem);
27 }
28
29 /**
30
Formats the invoice.
31 @return
the formatted invoice
32 */
33
public
String format()
34 {
35 String r =
Ð I N V O
I C E\n\nÑ
36 +
billingAddress.format()
37 + String.
format(
Ð\n\n%'-30s%'8s%'5s%'8s\nÑ
,
38
ÐDescriptionÑ,
ÐPriceÑ, ÐQtyÑ, ÐTotalÑ
);
39
40
for
(LineItem i : items)
41 {
42 r = r + i.format() +
Ð\nÑ
;
43 }
44
45 r = r + String.format(
Ð\nAMOUNT
DUE: %$'8.2fÑ
, getAmountDue());
46
47
return
r;
48 }
49
50 /**
51
Computes the total amount due.
52 @return
the amount due
53 */
54
public double
getAmountDue()