

내 코드
package myspace2;
import java.util.Scanner;
public class ProductOrderMain2 {
public static void main(String[] args) {
// ProductOrder2[] orders = new ProductOrder2[3];
// orders[0] = createorder("두부", 2000, 2);
// orders[1] = createorder("김치", 5000, 1);
// orders[2] = createorder("콜라", 1500, 2);
Scanner sc = new Scanner(System.in);
System.out.print("입력할 주문의 개수를 입력하세요:");
int num = sc.nextInt();
sc.nextLine(); //?
ProductOrder2[] orders = new ProductOrder2[num];
for (int i = 0; i < orders.length; i++) {
System.out.println( (i+1) + "번째 주문 정보를 입력하세요.");
System.out.print("상품명: ");
String productName = sc.nextLine();
System.out.print("가격: ");
int price = sc.nextInt();
System.out.print("수량: ");
int quantity = sc.nextInt();
sc.nextLine();
orders[i] = createorder(productName, price, quantity);
}System.out.println();
printOrders(orders);
int count = getcount(orders);
System.out.println("총 결제 금액: "+count);
}
static ProductOrder2 createorder(String productName, int price, int quantity) {
ProductOrder2 order = new ProductOrder2();
order.productName = productName;
order.price = price;
order.quantity = quantity;
return order;
};
static int getcount(ProductOrder2[] orders) {
int count = 0;
for(ProductOrder2 p: orders){
count += p.price * p.quantity;
}
return count;
}
static void printOrders(ProductOrder2[] orders) {
for(ProductOrder2 p: orders){
System.out.println("상품명:" + p.productName + ", 가격:" + p.price + ", 수량:" + p.quantity);
}
}
}