본문 바로가기
대학교/2.객체지향프로그래밍_JAVA

극장 예매 시스템

by Jcoder 2017. 4. 21.

소스 >

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
import java.util.*;
 
public class TheaterRevserve
{
    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.print("원하시는 좌석번호를 입력하세요(종료는 -1): ");
            Scanner scan = new Scanner(System.in);
            int s = scan.nextInt();
            if (s == -1)
                return;
            if (seats[s-1== 0)
            {
                seats[s-1= 1;
                System.out.println("예약되었습니다.");
            }
            else
            {
                System.out.println("이미 예약된 자리입니다.");
            }
        }
    }
}
cs

실행 결과 >

TheaterRevserve.java