-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInvoice.java
More file actions
58 lines (49 loc) · 1.49 KB
/
Invoice.java
File metadata and controls
58 lines (49 loc) · 1.49 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
58
import java.util.ArrayList;
public class Invoice {
private static final float tax_rate = 9.4f;
private static final int ORDER_REGISTERED = -1;
private static final int ORDER_PREPARING = 0;
private static final int ORDER_DISPATCHED = 1;
private static final int ORDER_DELIVERED = 2;
private final Customer customer;
private final ArrayList<Item> items;
private int state;
public Invoice(Customer customer) {
this.customer = customer;
this.items = new ArrayList<>();
this.state = ORDER_REGISTERED;
}
public boolean addItem(Item item) {
if (state != ORDER_REGISTERED || !items.contains(item)) {
return false;
}
items.add(item);
return true;
}
public boolean removeItem(Item item) {
if (items.contains(item)) {
items.remove(item);
return true;
}
return false;
}
public void nextStage() {
if (state < ORDER_DELIVERED) {
state++;
}
}
public int getState() {
return state;
}
public Customer getCustomer() {
return customer;
}
public int getTotalPrice() {
int totalPrice = 0;
for (Item item : items) {
totalPrice += item.getFood().getPrice() * item.getCount();
}
float taxAmount = (totalPrice * tax_rate) / 100;
return (int) Math.ceil(totalPrice + taxAmount);
}
}