-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInvoice.java
More file actions
57 lines (44 loc) · 1.22 KB
/
Invoice.java
File metadata and controls
57 lines (44 loc) · 1.22 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.Vector;
class Invoice {
private static final float tax_rate = 9.4f;
private int state;
private Customer customer;
private Vector<Item> items;
public Invoice(Customer customer) {
this.state = -1;
this.customer = customer;
this.items = new Vector<>();
}
public int getState() {
return state;
}
public Customer getCustomer() {
return customer;
}
public boolean addItem(Item item) {
if (state != -1)
return false;
items.add(item);
return true;
}
public boolean removeItem(Item item) {
if (state != -1)
return false;
return items.remove(item);
}
public void nextStage() {
state++;
}
public Vector<Item> getItems() {
return items;
}
public int getTotalPrice() {
int totalPrice = 0;
for (Item item : items) {
totalPrice += item.getFood().getPrice() * item.getCount();
}
float taxAmount = (totalPrice * tax_rate) / 100;
int totalPriceWithTax = Math.round(totalPrice + taxAmount);
return totalPriceWithTax;
}
}