ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Java] 명품 자바 프로그래밍(Java Programming) 4장 실습문제 6번
    CSE/Java 2015. 6. 13. 11:01

    Practice06.java

     

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    package ch03;
     
    import java.util.Scanner;
     
    public class Practice06 {
        @SuppressWarnings("resource")
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            Threater threater = new Threater();
     
            while (true) {
                System.out.print("예약(1) 조회(2) 취소(3) 끝내기(4) >> ");
                switch (scan.nextInt()) {
                case 1: {
                    System.out.print("좌석구분 S(1), A(2), B(3) >> ");
                    switch (scan.nextInt()) {
                    case 1:
                        threater.showS();
                        threater.reserve(1);
                        break;
     
                    case 2:
                        threater.showA();
                        threater.reserve(2);
                        break;
     
                    case 3:
                        threater.showB();
                        threater.reserve(3);
                        break;
                    }
     
                    break;
                }
     
                case 2: {
                    threater.showSeat();
                    break;
                }
     
                case 3: {
                    System.out.print("좌석구분 S(1), A(2), B(3) >> ");
                    switch (scan.nextInt()) {
                    case 1:
                        threater.showS();
                        threater.cancel(1);
                        break;
     
                    case 2:
                        threater.showA();
                        threater.cancel(2);
                        break;
     
                    case 3:
                        threater.showB();
                        threater.cancel(3);
                        break;
                    }
     
                    break;
                }
     
                case 4: {
                    System.exit(0);
                }
     
                default: {
                    System.out.println("잘못 입력 하셨습니다. 다시 입력해주세요.");
     
                }
                }
     
            }
        }
    }
     
    cs






    Threater.java

     

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
     
    package ch03;
     
    import java.util.Scanner;
     
    public class Threater {
        private String[] sClass = new String[10];
        private String[] aClass = new String[15];
        private String[] bClass = new String[20];
     
        Scanner scan;
     
        public Threater() {
            scan = new Scanner(System.in);
            for (int i = 0; i < bClass.length; i++) {
                if (i < 10) {
                    sClass[i] = "---";
                }
     
                if (i < 15) {
                    aClass[i] = "---";
                }
     
                bClass[i] = "---";
            }
        }
     
        public void reserve(int classNum) {
            String name = "";
            int seatNum = 0;
     
            System.out.print("이름 >> ");
            name = scan.next();
     
            System.out.print("번호 >> ");
            seatNum = scan.nextInt();
     
            try {
                switch (classNum) {
                case 1:
                    sClass[seatNum - 1] = name;
                    break;
     
                case 2:
                    aClass[seatNum - 1] = name;
                    break;
     
                case 3:
                    bClass[seatNum - 1] = name;
                    break;
                }
            } catch (IndexOutOfBoundsException e) {
                System.out.println("찾으시는 좌석 번호가 없습니다.");
            }
        }
     
        public void cancel(int classNum) {
            String name = "";
     
            System.out.print("이름 >> ");
            name = scan.next();
     
            switch (classNum) {
            case 1:
                for (int i = 0; i < sClass.length; i++) {
                    if (sClass[i].equals(name)) {
                        sClass[i] = "---";
                        return;
                    }
                }
     
                System.out.println("찾으시는 이름이 없습니다.");
     
                break;
     
            case 2:
                for (int i = 0; i < aClass.length; i++) {
                    if (aClass[i].equals(name)) {
                        aClass[i] = "---";
                        return;
                    }
                }
     
                System.out.println("찾으시는 이름이 없습니다.");
     
                break;
     
            case 3:
                for (int i = 0; i < bClass.length; i++) {
                    if (bClass[i].equals(name)) {
                        bClass[i] = "---";
                        return;
                    }
                }
     
                System.out.println("찾으시는 이름이 없습니다.");
     
                break;
            }
        }
     
        public void showS() {
            System.out.print("S>>");
            for (int i = 0; i < sClass.length; i++) {
                System.out.print(sClass[i] + " ");
            }
     
            System.out.println();
     
        }
     
        public void showA() {
            System.out.print("A>>");
            for (int i = 0; i < aClass.length; i++) {
                System.out.print(aClass[i] + " ");
            }
     
            System.out.println();
        }
     
        public void showB() {
            System.out.print("B>>");
            for (int i = 0; i < bClass.length; i++) {
                System.out.print(bClass[i] + " ");
            }
            System.out.println();
        }
     
        public void showSeat() {
            showS();
            showA();
            showB();
            System.out.println("\n 조회를 완료하였습니다.");
        }
    }
     
    cs









    실행 결과:












    댓글

Designed by Tistory.