-
Notifications
You must be signed in to change notification settings - Fork 30
/
Invoice.java
58 lines (56 loc) · 1.36 KB
/
Invoice.java
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.ArrayList;
public class Invoice {
private int state;
private Customer customer;
private ArrayList<Item> items;
public Invoice(Customer customer) {
setCustomer(customer);
setState(-1);
setItems();
}
private void setCustomer(Customer customer) {
this.customer = customer;
}
public Customer getCustomer() {
return customer;
}
private void setState(int state) {
this.state = state;
}
public int getState() {
return state;
}
private void setItems() {
this.items = new ArrayList<>();
}
public ArrayList<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.remove(item);
return true;
}
return false;
}
public void nextStage() {
if(state < 2) {
state++;
}
}
public int getTotalPrice() {
int totalPrice = 0;
for(Item item : items) {
totalPrice += (item.getCount() * item.getFood().getPrice());
}
double totalTax = ((totalPrice * 9.4) / 100);
return (int)Math.ceil(totalPrice + totalTax);
}
}