-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductOrderMain2.java
More file actions
38 lines (32 loc) · 1.2 KB
/
Copy pathProductOrderMain2.java
File metadata and controls
38 lines (32 loc) · 1.2 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
package ref.ex;
public class ProductOrderMain2 {
public static void main(String[] args) {
ProductOrder[] orders = new ProductOrder[3];
orders[0] = createOrder("두부", 2000, 2);
orders[1] = createOrder("김치", 5000, 1);
orders[2] = createOrder("콜라", 1500, 2);
int totalAmount = 0;
printOrders(orders);
int totalAmount1 = getTotalAmount(orders);
System.out.println("총 가격 : " + totalAmount);
}
public static ProductOrder createOrder(String productname, int price, int quantity) {
ProductOrder order = new ProductOrder();
order.productName = productname;
order.price = price;
order.quantity = quantity;
return order;
}
public static void printOrders(ProductOrder[] orders) {
for (ProductOrder s : orders) {
System.out.println("상품명 : " + s.productName + ", 가격 : " + s.price + ", 수량 : " + s.quantity);
}
}
public static int getTotalAmount(ProductOrder[] orders) {
int totalAmount = 0;
for (ProductOrder order : orders) {
totalAmount += order.price * order.quantity;
}
return totalAmount;
}
}