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