ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [개인프로젝트] 키오스크 만들기 최종
    스파르타코딩클럽/자바 개인프로젝트 - Kiosk 2023. 10. 23. 14:30
    switch (choice) {
            case 0:
                System.out.println(menuList.get(choice));
                System.out.println("     주문목록에 담으시겠습니까?");
                System.out.println("       1.네    2.아니오");
                int pick = sc.nextInt();
                sc.nextLine();
                if (pick == 1) {
                    System.out.println("주문목록에 담았습니다.");
                    addOrder(menuList.get(choice), 1);
                } else {
                    System.out.println("취소되었습니다.");
                }
                break;
    
            case 1:
                System.out.println(menuList.get(choice));
                System.out.println("     주문목록에 담으시겠습니까?");
                System.out.println("       1.네    2.아니오");
                int pick2 = sc.nextInt();
                sc.nextLine();
                if (pick2 == 1) {
                    System.out.println("주문목록에 담았습니다.");
                    addOrder(menuList.get(choice), 1);
                } else {
                    System.out.println("취소되었습니다.");
                }
                break;
    
            case 2:
                System.out.println(menuList.get(choice));
                System.out.println("     주문목록에 담으시겠습니까?");
                System.out.println("        1.네    2.아니오");
                int pick3 = sc.nextInt();
                sc.nextLine();
                if (pick3 == 1) {
                    System.out.println("주문목록에 담았습니다.");
                    addOrder(menuList.get(choice), 1);
                } else {
                    System.out.println("취소되었습니다.");
                }
                break;
        }
              */

     

    이러한 중복되는 switch문을 아래처럼 변경하였다.

     

    private void addOrderMenu(ArrayList<? extends Menu> menuList, Scanner sc, int choice) {
            System.out.println(menuList.get(choice));
            System.out.println("     주문목록에 담으시겠습니까?");
            System.out.println("       1.네    2.아니오");
            int chooseMenu = sc.nextInt();
            sc.nextLine();
            if (chooseMenu == 1) {
                System.out.println("주문목록에 담았습니다.");
                addOrder(menuList.get(choice), 1);
            } else {
                System.out.println("취소되었습니다.");
    
            }
        }
    
        public void pickMenu(ArrayList<? extends Menu> menuList) {
            Scanner sc = new Scanner(System.in);
            int inputChoice = sc.nextInt();
            int choice = inputChoice - 1;
            sc.nextLine();
            if (choice < 0 || choice > 2) {
                return;
            }
            addOrderMenu(menuList, sc, choice);
        }
    
    
        public void pickMainMenu(ArrayList<? extends Menu> menuList) {
            Scanner sc = new Scanner(System.in);
            int inputChoice = sc.nextInt();
            int choice = inputChoice - 1;
            sc.nextLine();
            if (choice < 0 || choice > 2) {
                return;
            }
            addOrderMainMenu(menuList, sc, choice);
        }
    
        private void addOrderMainMenu(ArrayList<? extends Menu> menuList, Scanner sc, int choice) {
            System.out.println(menuList.get(choice));
            System.out.println("     주문목록에 담으시겠습니까?");
            System.out.println("       1.네    2.아니오");
            int chooseMenu = sc.nextInt();
            sc.nextLine();
            if (chooseMenu == 1) {
                System.out.println("주문목록에 담았습니다.");
                addOrder(menuList.get(choice), 1);
                System.out.println("\n선택하신 상품에 메뉴를 추가하시겠습니까?");
                System.out.println("원하시는 상품이 없다면 5번을 눌러주세요\n");
                choiceMenu(main.topping);
                plusMenu(main.topping);
            } else {
                System.out.println("취소되었습니다.");
    
            }
        }

     

    오늘 ReadMe를 작성하기 위해 마지막으로 실행해보던 중 엄청난 에러를 발견했다.

     

    메인메뉴 떡볶이를 주문목록에 담지 않기를 선택하더라도 토핑목록이 뜨는 대참사가 난 것이다.

    이게 메인클래스에서 메인메뉴 주문메소드와 토핑메뉴 주문메소드를 따로 구분지어서 그런 것이었는데.

    이걸 왜 제출 당일에 알았는지 모르겠다.

     

    급하게 부랴부랴 어떻게 해결해야할지 머리를 굴렸고

    addOrderMenu의 chooseMenu 변수가 1일때만 plusMenu를 동작시키면 되지 않을까라는 생각에 이르렀다.

     

    하지만 chooseMenu 변수를 가져오는 적절한 방법을 찾지 못해서 폐기

     

     

    pickMenu에서 하위에 if문을 적절히 넣어보려 했으나

     

    이건 오히려 떡볶이가 주문목록에 담기지 않는 대참사가 추가로 발생했다.

     

     

    그래서 그냥 메인메뉴 전용 주문 메소드를 만들고 그 안에 토핑메뉴 주문목록을 집어넣는것으로 마무리 지었다.

     

     

    또한 5번 주문목록을 눌렀을때  

    1,주문하기   2. 돌아가기

     

    1, 2  두 선택지만 작동해야하는데
    조건문을 똑바로 하지 않아서 다른 숫자를 눌러도 돌아가지고

    문자를 입력하면 에러가 떴다.

     

    그래서 할 수 있는 최선의 방법인 try-catch문으로 싹 다 묶어주고  경고문만 띄우는 식으로 처리하고 제출하였다..

     

     

     

     

    제출 후 느낀 점

     

    생각보다 쉽지않았다.

    이론을 빠삭하게 알아봤자 적용을 못하면 끝이라는 걸 실감했다.

    백문이 불여일타,  강의만 듣는게 아니라 코드를 쳐보는게 더 중요하다는 말의 의미를 뼈저리게 깨달은 프로젝트였다.

     

    그리고 람다와 스트림 쪽은 몰라도 된다고 하셨지만 그 부분도 잘 알았다면 좀 더 다양한 방식을 시도할 수 있었을 것 같다.

     

     

Designed by Tistory.