

출력 예시
상품명: 두부, 가격: 2000, 수량: 2 상품명: 김치, 가격: 5000, 수량: 1 상품명: 콜라, 가격: 1500, 수량: 2 총 결제 금액: 12000
package ref.ex;
public class ProductOrder {
String productName;
int price;
int quantity;
}
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);
printOrders(orders);
int totalAmount = getTotalAmount(orders);
System.out.println("총 결제 금액: " + totalAmount);
}
static ProductOrder createOrder(String productName, int price, int quantity) {
ProductOrder order = new ProductOrder();
order.productName = productName;
order.price = price;
order.quantity = quantity;
return order;
}
static void printOrders(ProductOrder[] orders) {
for (ProductOrder order : orders) {
System.out.println("상품명: " + order.productName + ", 가격: " +
order.price + ", 수량: " + order.quantity);
}
}
static int getTotalAmount(ProductOrder[] orders) {
int totalAmount = 0;
for (ProductOrder order : orders) {
totalAmount += order.price * order.quantity;
}
return totalAmount;
}
}