-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInvoice.java
More file actions
50 lines (49 loc) · 1.22 KB
/
Invoice.java
File metadata and controls
50 lines (49 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
import java.util.Vector;
class Invoice {
private static final float taxRate = 0.094f;
private Customer customer;
private int state;
private Vector<Item> items;
private int price;
private Item item;
public Invoice(Customer customer) {
this.customer = customer;
this.state = -1;
this.items = new Vector<>();
}
public int getState(){
return state;
}
public Customer getCustomer(){
return customer;
}
public Vector<Item> getItems(){
return items;
}
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)) {
return items.remove(item);
}
return false;
}
public void nextStage() {
if (state < 2) {
state++;
}
}
public int getTotalPrice() {
double total = 0.0;
for (Item item : items) {
total += (item.getFood().getPrice()) * item.getCount();
}
double totalTax = total * taxRate;
return (int) Math.ceil(total + totalTax);
}
}