-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart.java
More file actions
24 lines (23 loc) · 718 Bytes
/
Copy pathCart.java
File metadata and controls
24 lines (23 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package java_assign2;
import java.util.*;
class Cart {
private List<CartItem> items = new ArrayList<>();
public void addItem(MenuItem item, int qty) {
for (CartItem ci : items) {
if (ci.getItem().equals(item)) { ci.setQuantity(ci.getQuantity() + qty); return; }
}
items.add(new CartItem(item, qty));
}
public double getTotal(double taxRate, double fees) {
double total = 0;
for (CartItem ci : items) total += ci.getTotal();
total += total * taxRate; total += fees;
return total;
}
public List<CartItem> getCartItems() {
return items;
}
public void clear() {
items.clear();
}
}