본문 바로가기
TIL/내배캠 과제

23.06.07

by J1-H00N 2023. 6. 7.

일단 전에 만든 코드에서

AllReservation allReservation = new AllReservation(new HashMap<>());

이 부분을 혹시 모를 초기화를 대비해 메서드 밖으로 빼냈다.

 

예약 정보를 제대로 출력하기 위해 Reservation에 toString문을 추가했다.

public String toString() {
        return String.format("예약자 분 성함 : %s\n예약자 분 전화번호 : %s\n예약한 방 번호 : %d\n예약일자 : %s",
                guest.getGuestName(), guest.getPhoneNum(), roomNum, reservationDate);
    }

여기서 고민인건 예약번호의 출력 여부

 

또한 예약 목록이 비어있을 경우를 고려해 예외처리를 했다.

try {
            for (Map.Entry<String, Reservation> allReservation : allReservation.getReservaitonHashMap().entrySet()) {
                String reservationId = allReservation.getKey();
                Reservation reservation = allReservation.getValue();
                System.out.println(reservationId + "\n" + reservation.toString());
            }
        } catch (Exception e) {
            // 예외 처리
            System.out.println("예약 목록이 없습니다.");
        }

 

위 방법은 entrySet이 비어있는 경우에는 공백을 출력하므로 예약목록이 비어있는 경우에 대한 예외처리가 불가능하다.

따라서 예외처리 없이 if 문으로 정리했다.

        if (allReservation.getReservaitonHashMap().isEmpty()) {
            System.out.println("예약 목록이 없습니다.");
        } else {
            for (Map.Entry<String, Reservation> allReservation : allReservation.getReservaitonHashMap().entrySet()) {
                String reservationId = allReservation.getKey();
                Reservation reservation = allReservation.getValue();
                System.out.println(reservationId + "\n" + reservation.toString());
            }
        }

 

위 구현을 끝내고 개인공부를 하던 와중에 팀에서 프로젝트의 flow chart를 그려보자는 의견이 나와 작업을 하게 되었다.

그리고 flow chart를 만드면서 예약 목록 조회와 삭제의 로직이 대부분 겹치는 사실을 발견해 두 기능을 하나의 흐름에서 해결하기로 했다. 또한, 추가기능 구현에 대한 얘기가 나오며 호텔 측에서 특정 예약을 취소시킬 수 있는 기능과 전체 예약 count와 호텔의 자산 출력을 구현하기로 했다. 이는 아이디어의 발안자이며 현재 구현을 끝낸 내가 맡기로 했다.

 

전체 예약 count와 호텔의 자산 출력

System.out.println("현재 예약된 방의 수 : " + allReservation.getReservaitonHashMap().size());
            System.out.println("현재 호텔 예상 매출 : " + hotel.getAsset());

 

호텔 측에서 특정 예약을 취소시킬 수 있는 기능

while (true) {
                System.out.println("\n---------------------------------------------\n");
                System.out.println("1. 프로그램 종료하기     2. 예약 취소하기\n");
                System.out.println("숫자를 입력해주세요. : ");
                Scanner sc = new Scanner(System.in);
                int check = sc.nextInt();
                try {
                    if (check == 1) {
                        System.out.println("프로그램이 종료됩니다.");
                        Thread.sleep(3000); // 3초 정지 후 프로그램 종료
                        return;
                    } else if (check == 2) {
                        // 예약 목록 조회(취소) 메서드
                        break;
                    } else { // 다른 숫자를 입력받았을 때
                        System.out.println("잘못된 입력입니다.");
                        sc.nextLine(); // 버퍼 지우기
                    }
                } catch (InputMismatchException e) { // 숫자 외에 입력을 받았을 때
                    System.out.println("잘못된 입력입니다. 숫자를 입력해주세요.");
                    sc.nextLine();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

 

수업이 끝나기 전 마지막 회의에서 guest 클래스의 의의를 살리기 위해 회원가입/로그인 기능을 만들어 게스트를 통해 게스트의 정보를 저장하는 회원가입 공간을 만들기로 했다. 할일이 없는 제가 회원가입/로그인 기능을 구현하기로 했습니다.

'TIL > 내배캠 과제' 카테고리의 다른 글

23.06.09  (0) 2023.06.09
23.06.08  (0) 2023.06.08
23.06.05  (0) 2023.06.05
23.06.03  (0) 2023.06.05
23.06.02  (0) 2023.06.02