-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductOrderMain3.java
More file actions
53 lines (44 loc) · 1.74 KB
/
Copy pathProductOrderMain3.java
File metadata and controls
53 lines (44 loc) · 1.74 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
package ref.ex;
import java.util.Scanner;
public class ProductOrderMain3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("입력할 주문의 개수를 입력하세요 : ");
int n = scanner.nextInt(); // \n
scanner.nextLine();
ProductOrder[] orders = new ProductOrder[n];
for(int i = 0 ; i < n; i++) {
System.out.println((i + 1) + "번째 주문 정보를 입력허세요.");
System.out.print("상품명 : ");
String productName = scanner.nextLine();
System.out.print("가격 : ");
int price = scanner.nextInt();
System.out.print("수량 : ");
int quantity = scanner.nextInt();
scanner.nextLine();
orders[i] = createOrder(productName, price, quantity);
}
printOrders(orders);
int totalAmount1 = getTotalAmount(orders);
System.out.println("총 가격 : " + totalAmount1);
}
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;
}
}