-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart.py
More file actions
56 lines (41 loc) · 1.66 KB
/
Cart.py
File metadata and controls
56 lines (41 loc) · 1.66 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
# Cart class는 장바구니와 관련된 기능이 포함된 class
# 장바구니 출력, 수정, 삭제 등의 로직 선언
# ※ 모듈화를 위한 Class 설계
class Cart:
# 생성자. 장바구니 목록 멤버 변수 선언
def __init__(self):
self.cartList = []
# 장바구니 메뉴 개수 반환 함수
def getCartCount(self):
return len(self.cartList)
# 장바구니 메뉴 총합 개수 반환 함수
def getCartTotalCount(self):
totalCount = 0
for index in range(0, self.getCartCount()):
totalCount += self.cartList[index].getCount()
return totalCount
# 장바구니 총합 금액 반환 함수
def getCartPrice(self):
totalPrice = 0
for index in range(0, self.getCartCount()):
totalPrice += self.cartList[index].getPrice()
return totalPrice
# 장바구니 Menu 추가 함수
def addMenu(self, menu):
self.cartList.append(menu)
# 장바구니 Menu 삭제 함수
def delMenu(self, index):
del self.cartList[index]
# 장바구니 Menu 개수 변경 함수
def updateMenuCount(self, index, value):
self.cartList[index].setCount(value)
# 장바구니 목록 출력 함수
def printCart(self):
for index in range(0, self.getCartCount()):
print(str(index+1) + ". ", end="")
self.cartList[index].printMenu()
# 장바구니 정보 출력 함수
def printCartInfo(self):
print("메뉴 종류 : " + str(self.getCartCount()))
print("총 개수 : " + str(self.getCartTotalCount()))
print("총합 가격 : " + str(self.getCartPrice()))