hyeonga_code

Java_룸 예약 시스템 작성하기 본문

Java

Java_룸 예약 시스템 작성하기

hyeonga 2023. 10. 31. 05:59
반응형

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
import java.util.*;
 
class RoomMG {
    boolean room[];
    int roomSu;
    Scanner in;
 
    RoomMG() {
        // 생성사 생성
        in = new Scanner(System.in);
        System.out.print("Room count: ");
        roomSu = in.nextInt();
        room = new boolean[roomSu];
    }
 
    void input() {
        int roomNum;
        while (true) {
            System.out.println("Room number: ");
            roomNum = in.nextInt();
            if (roomNum <1 || roomNum > roomSu) {
                System.out.printf("Please choose from 1 to %d!", roomSu);
                continue;
            }
            else {
                break;
            }
        }
        if (room[roomNum - 1]) {
            System.out.println(roomNum + " room is full.");
        }
        else {
            room[roomNum - 1= true;
            System.out.println("Enter room " + roomNum + ".");
        }
    }
 
    void output() {
        int roomNum;
        while (true) {
            System.out.print("Checkout room number: ");
            roomNum = in.nextInt();
            if (roomNum <1 || roomNum > roomSu) {
                System.out.printf("Please choose 1 to %d!");
                continue;
            }
            else {
                break;
            }
        }
        if (room[roomNum - 1]) {
            room[roomNum - 1= false;
            System.out.println("Checkout room " + roomNum + ".");
        }
        else {
            System.out.println(roomNum + " room is empty.");
        }
    }
 
    void view() {
        for (int i = 0; i < roomSu; ++i) {
            if (room[i]) {
                System.out.println(i + 1 + " room is full.");
            }
            else {
                System.out.println(i + 1 + " room is empty.");
            }
        }
    }
 
    void exit() {
        System.out.println("End Program.");
        System.exit(0);
    }
}
 
public class same {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        RoomMG mg = new RoomMG();
        while (true) {
            System.out.print("1.Enter 2.Checkout 3.View 4.End : ");
            int select = in.nextInt();
            int roomNum;
            switch (select) {
            case 1:
                mg.input();
                break;
            case 2:
                mg.output();
                break;
            case 3:
                mg.view();
                break;
            case 4:
                mg.exit();
            default:
                System.out.println("Wrong!");
            }
        }
    }
}
반응형