-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShoppingCart.java
35 lines (29 loc) · 1016 Bytes
/
ShoppingCart.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
package oopIntro;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Enumeration;
public class ShoppingCart {
private static Hashtable<Integer, Item> cartItems = new Hashtable<>();
private StoreItems storeItems = new StoreItems();
public void addToCart(int itemId) {
Item item = storeItems.getById(itemId);
cartItems.put(item.getProductId(),item);
System.out.println("sepete eklendi" + item.getProductName());
}
public void dropFromCart(int itemId) {
Item item = storeItems.getById(itemId);
cartItems.remove(itemId);
System.out.println("sepetten silindi" + item.getProductName());
}
public double getTotalPrice() {
double totalPrice = 0;
Enumeration<Integer> e = cartItems.keys();
while (e.hasMoreElements()) {
int key = e.nextElement();
Item item = cartItems.get(key);
totalPrice = totalPrice + item.getSurchargePrice();
}
return totalPrice;
}
}