-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoice.java
42 lines (37 loc) · 1 KB
/
Invoice.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import javax.sound.sampled.Line;
import java.util.ArrayList;
public class Invoice {
private Address billingAddress;
private ArrayList<LineItem> items;
public Invoice(Address anAddress)
{
items = new ArrayList<LineItem>();
billingAddress = anAddress;
}
public void add(Product aProduct, int quantity)
{
LineItem anItem = new LineItem(aProduct, quantity);
items.add(anItem);
}
public String format()
{
String r = " I N V O I C E \n\n"
+ billingAddress.format()
+String.format("\n\n%-30s%8s%5s%8s\n", "Description", "Price", "Qty", "Total");
for (LineItem item:items)
{
r=r+item.format() + "\n";
}
r = r + String.format("\n Amount due: $%8.2f", getAmountDue());
return r;
}
public double getAmountDue()
{
double amountDue = 0;
for (LineItem item : items)
{
amountDue = amountDue + item.getTotalPrice();
}
return amountDue;
}
}