-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInvoice.java
More file actions
75 lines (62 loc) · 1.63 KB
/
Invoice.java
File metadata and controls
75 lines (62 loc) · 1.63 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.Vector;
public class Invoice {
private static final float tax_rate = 0.094f;
private int state;
private final Customer customer;
private final Vector<Item> items;
private float totalPrice;
public Invoice(Customer customer) {
this.state = -1;
this.customer = customer;
this.items = new Vector<>();
this.totalPrice = 0.0f;
}
public int getState() {
return state;
}
public Customer getCustomer() {
return customer;
}
public boolean addItem(Item item) {
if (state == -1) {
items.add(item);
calculateTotalPrice();
return true;
}
else {
return false;
}
}
public boolean removeItem(Item item) {
int i = 0;
if (state == -1) {
for (Item currItem : items) {
if (currItem.getFood().equals(item.getFood())) {
items.remove(i);
calculateTotalPrice();
return true;
}
i++;
}
}
return false;
}
public void nextStage() {
state++;
}
public Vector<Item> getItems() {
return items;
}
public int getTotalPrice() {
return (int) Math.ceil(totalPrice);
}
private void calculateTotalPrice() {
totalPrice = 0.0f;
for (Item item : items) {
// add up all prices
totalPrice += item.getCount() * item.getFood().getPrice();
}
// totalprice + calculated tax
totalPrice += totalPrice * tax_rate;
}
}