1 /**
2 A simple invoice formatter.
3 */
4 public class SimpleFormatter implements InvoiceFormatter
5 {
6 public String formatHeader()
7 {
8 total = 0;
9 return " I N V O I C E\n\n\n";
10 }
11
12 public String formatLineItem(LineItem item)
13 {
14 total += item.getPrice();
15 return (String.format(
16 "%s: $%.2f\n",item.toString(),item.getPrice()));
17 }
18
19 public String formatFooter()
20 {
21 return (String.format("\n\nTOTAL DUE: $%.2f\n", total));
22 }
23
24 private double total;
25 }