-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductAdminEx.java
More file actions
49 lines (43 loc) · 1.71 KB
/
Copy pathProductAdminEx.java
File metadata and controls
49 lines (43 loc) · 1.71 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
package array.ex;
import java.util.Scanner;
public class ProductAdminEx {
public static void main(String[] args) {
int maxProduct = 3;
String[] productNames = new String[maxProduct];
int[] productPrices = new int[maxProduct];
int productCount = 0;
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.print( "1. 상품 등록 | 2. 상품 목록 | 3. 종료 \n 메뉴를 선택하세요 : ");
int menu = scanner.nextInt();
scanner.nextLine(); // \n
if (menu == 1) {
if (productCount >= maxProduct){
System.out.println("더 이상 상품을 등록할 수 없습니다.");
continue;
}
System.out.println("상품 이름을 입력하세요 : ");
productNames[productCount] = scanner.nextLine();
System.out.println("상품 가격을 입력하세요 : ");
productPrices[productCount] = scanner.nextInt();
productCount++;
}
else if (menu == 2) {
if(productCount == 0) {
System.out.println("등록된 상품이 없습니다. ");
continue;
}
for(int i = 0; i < productCount; i++) {
System.out.println(productNames[i] + " : " + productPrices[i] + "원");
}
}
else if(menu ==3) {
System.out.println("프로그램을 종료합니다.");
break;
}
else {
System.out.println("잘못된 메뉴를 선택하셨습니다.");
}
}
}
}