-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheaterReserve.java
More file actions
52 lines (44 loc) · 1.23 KB
/
Copy pathTheaterReserve.java
File metadata and controls
52 lines (44 loc) · 1.23 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
// 극장 예약 시스템 (= 좌석 10개, 예약 o = 1, 예약 x = 0)
// 예약 취소 추가
import java.util.Scanner;
public class TheaterReserve {
public static void main(String[] args) {
final int size = 10;
int[] seats = new int[size];
while(true) {
System.out.println("-----------------------");
for(int i=0; i<size; i++) {
System.out.print(i+1 + " ");
}
System.out.println("\n-----------------------");
for(int i = 0;i<size;i++) {
System.out.print(seats[i] + " ");
}
System.out.println("\n-----------------------");
System.out.println("원하시는 좌석번호를 입력하세요(종료는 -1, 예약 취소는 0): ");
Scanner scan = new Scanner(System.in);
int s = scan.nextInt();
if(s == -1) {
System.out.println("종료되었습니다.");
break;
}
else if(s == 0) {
System.out.println("예약 취소 메뉴 입니다. 취소할 번호를 입력하세요.");
int change = scan.nextInt();
if(seats[change-1] == 1) {
seats[change-1] = 0;
}
else {
System.out.println("예약된 좌석이 아닙니다. 다시 0을 입력해주세요.");
}
}
else if(seats[s-1] == 0) {
seats[s-1] = 1;
System.out.println("예약되었습니다.");
}
else {
System.out.println("이미 예약된 자리입니다.");
}
}
}
}