-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShoppingCart.java
More file actions
32 lines (29 loc) · 962 Bytes
/
Copy pathShoppingCart.java
File metadata and controls
32 lines (29 loc) · 962 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
25
26
27
28
29
30
31
32
package access.ex;
public class ShoppingCart {
private Item[] items = new Item[10];
private int itemCount;
public void addItem(Item item) {
if (itemCount >= items.length){
System.out.println("장바구니가 가득 찼습니다.");
return;
}
items[itemCount] = item;
itemCount++;
}
public void displayItems() {
System.out.println("장바구니 상품 출력");
for (int i = 0; i <itemCount; i++) {
Item item = items[i];
System.out.println("상품명 : " + item.getName() + ", 합계 : " + item.getTotalPrice());
}
System.out.println("전체 가격 합 : " + calculateTotalPrice());
}
private int calculateTotalPrice(){
int totalPrice = 0;
for(int i = 0; i < itemCount; i++) {
Item item = items[i];
totalPrice += item.getTotalPrice();
}
return totalPrice;
}
}