Light Blue Pointer
본문 바로가기
Developing/Journal

[내일배움캠프][Team Project]키오스크 개발일지

by Greedy 2023. 10. 24.

https://github.com/minisundev/Kiosk

 

GitHub - minisundev/Kiosk: Kiosk program for a burger place

Kiosk program for a burger place. Contribute to minisundev/Kiosk development by creating an account on GitHub.

github.com

 

개인프로젝트로 만들었던 키오스크에 기능을 더해서 추가로 개발하는걸 팀 프로젝트로 한다고 한다

사실 나는 호텔 예약 프로그램으로 아예 새로운 걸 개발하고 싶었으나 팀원들이 키오스크 주제로 다시 하고싶다 해서 하게 됐다

코드 보다보니 추가기능까지 한 건 나밖에 없어서 내 코드 위에 추가 기능을 구현하게 되었다

노란색 형광펜을 친 부분이 새로 개발할 부분이다

  • 키오스크 관리 프로그램
    1. 상점은 메뉴와 상품을 가진다.
    2. 메뉴는 메뉴명과 메뉴설명 그리고 여러개의 상품을 가진다.
    3. 상품은 상품명과 상품설명 그리고 가격을 가진다.
    4. 주문은 주문상품 목록과 수량 그리고 총가격을 가진다.
    5. 고객은 상점의 키오스크 프로그램을 통해 상품 주문을 하고 대기번호를 받는다.
      • (기존)메인 메뉴
      (신규)주문 현황
      • 맨 위에 완료된 최근주문 3개를 출력한다.
      • 그 아래에 대기중인 모든 주문 목록을 출력한다.
      • (기존)상품 메뉴
      • (기존)구매 화면
      (개선)주문 화면
        • 주문시 요청사항 메시지를 입력할 수 있습니다. (20자 제한)
      • (기존)주문완료 화면
      • (기존)주문취소 화면
    6. (개선) 키오스크 프로그램
    7. 상점은 키오스크 관리 프로그램을 통해 메뉴와 상품을 등록/삭제하고 주문을 수신/완료한다.
      1. 메인 메뉴
      • 메인 메뉴에서 아래 기능을 실행한다.
        • “1. 대기주문 목록”
        • “2. 완료주문 목록”
        • “3. 상품 생성”
        • “4. 상품 삭제”
      1. 대기주문 목록
      • 주문이 완료되어 처리 대기중인 주문을 조회하고 완료처리 할 수 있다.
      • 주문 데이터 형식은 아래와 같다.
        1. 대기 번호
        2. 주문 상품 목록
        3. 주문 총 가격
        4. 요청 사항
        5. 주문 일시
        6. 날짜는 ISO 8601 형식으로 조합된 UTC 날짜 및 시간 예) 2016-10-27T17:13:40+00:00
      • [ 주문 데이터 ]
      1. 완료 주문목록
      • 완료처리 했던 주문들을 모두 조회할 수 있다.
      • **[ 완료주문 데이터 ]**는 **[ 주문 데이터 ]**에 완료 일시를 추가로 가진다.
      • [ 완료주문 데이터 ]
        1. 대기 번호
        2. 주문 상품 목록
        3. 주문 총 가격
        4. 주문 일시
        5. 요청 사항
        6. 완료주문 일시
        7. 날짜는 ISO 8601 형식으로 조합된 UTC 날짜 및 시간 예) 2016-10-27T17:13:40+00:00
      1. 상품 생성
      • 새로운 상품정보(메뉴, 이름, 설명, 가격)을 입력하여 생성할 수 있다.
      • 기존에 없는 메뉴라면 신규로 생성해준다.
      • 새로 생성된 메뉴와 상품은 각각 유일한 메뉴ID, 상품ID 식별자를 가진다.
      1. 상품 삭제
      • 상품ID를 가지고 기존 상품정보를 삭제할 수 있다.
      • 삭제이전에 주문된 주문정보에서는 삭제 되지 않는다.
    8. (신규) 키오스크 관리 프로그램

 

10/24

새 기능을 보다 보니까, 그리고 그 전에 개발한게 딱히 정리가 싸악 된 느낌은 아니라서 추가로 구현할 기능에 더 편리하게 이용될 수 있게 이미 개발한 것을 더 정리하는 시간을 가졌다

 

일단 메인에서 함수들을 빼고 키오스크 앱이랑 관리자 앱으로 분리함

public static void main(String args[]){

        int select;
        while(true){
            Scanner sc = new Scanner(System.in);
            System.out.println("SHAKESHACK BURGER 에 오신걸 환영합니다.\\n" +
                    "접속할 앱을 선택해 주세요.\\n" +
                    "1. 주문         | 주문\\n" +
                    "2. 관리  | 매장 관리\\n"
            );
            select = sc.nextInt();

            switch(select){
                case 1 : KioskApp.run();
                    break;
                case 2 : ManagerApp.run();
                    break;
                default:
                    System.out.println("다시 선택해 주세요");
            }
        }
    }

배열을 리스트로 변경함

Q. private static ArrayList<Interger> *count* = new ArrayList<Interger>(0,0,0);

이거 왜 에러 안 나지?

⭐리스트 초기화

ArrayList<Type> str = new ArrayList<Type>();
       str.add("Geeks");
       str.add("for");
       str.add("Geeks");

Initialization using asList()

ArrayList<String> gfg = new ArrayList<String>(
            Arrays.asList("Geeks",
                          "for",
                          "Geeks"));
 
        // print ArrayList
        System.out.println("ArrayList : " + gfg);
    }

Initialization using List.of() method

ArrayList<String> gfg = new ArrayList<String>(
            Arrays.asList("Geeks",
                          "for",
                          "Geeks"));

Initialization using List.of() method

// Java code to illustrate initialization
// of ArrayList using List.of() method
 
import java.util.*;
 
public class GFG {
    public static void main(String args[])
    {
 
        // create a ArrayList String type
        // and Initialize an ArrayList with List.of()
        List<String> gfg = new ArrayList<>(
            List.of("Geeks",
                    "for",
                    "Geeks"));
 
        // print ArrayList
        System.out.println("ArrayList : " + gfg);
    }
}

Initialization using  stream() and collect() methods

// create a stream of elements using Stream.of()
        // method collect the stream elements into an
        // ArrayList using the collect() method and
        // Collectors.toCollection() method
        ArrayList<String> list
            = Stream.of("Geeks", "For", "Geeks")
                  .collect(Collectors.toCollection(
                      ArrayList::new));
 
        System.out.println(list); // print the ArrayList
    }

 

🚩문제 : 모듈에 문제가 생겼다고 함

IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?

⛳해결

I had the same problem and found out that my src wasn't marked as Sources Root. To change this:

  • right-mouse click on your src
  • navigate to "Mark Directory As"
  • choose "Sources Root" It will now recognize your files correctly and your main classes will be able to run again

 

한번 정리해봄

import java.util.ArrayList;
import java.util.Arrays;

public class Drink extends Product {

    private static ArrayList<Drink> drinks = new ArrayList<>(Arrays.asList(
            new Drink("Raspberry Lemonade","쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",6.5),
            new Drink("Lemonade","매장에서 직접 만드는 상큼한 레몬에이드", 6.5),
            new Drink("Fresh Brewed Iced Tea","직접 유기농 홍차를 우려낸 아이스 티",5.4)
            )
    );

    public Drink(int select) {
        int index = select-1;
        //id 일치하는 상품 count만 올림

        drinks.get(index).setCount(drinks.get(index).getCount()+1);

    }
    public Drink(){

    }

    public Drink(String name, String desc, double price){//새로 생성하는 생성자
        super.setName(name);
        super.setId(drinks.size());
        super.setDesc(desc);
        super.setCount(0);
    }

    public void printDescTotal() {
        int productCount = 0;
        for (Drink d : drinks) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (d.getName() == super.getName()) {
                productCount = d.getCount();
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

    public void printDesc() {
        System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
    }

    public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Drinks MENU ]\\n");
        for (int i = 0; i < drinks.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + drinks.get(i).getName() + "   | W " + drinks.get(i).getPrice() + " | " + drinks.get(i).getDesc());
        }
    }

    public static void printProductCount() {//버거별로 개수랑 같이 주문 화면에 목록 출력
        for (Drink d : drinks) {//for문 돌면서 있으면 출력
            if(d.getCount()>1){//2개 이상이면 숫자도 출력
                System.out.println(". " + d.getName() + "   | W " + d.getPrice() + " | " + d.getCount() + " | " + d.getDesc());
            }else if(d.getCount()>0) {
                System.out.println(". " + d.getName() + "   | W " + d.getPrice() + " | " + d.getDesc());
            }
        }
    }

    public static void clear() {//count 비우는 함수
        for (Drink d : drinks) {//for문 돌면서 있으면 출력
            d.setCount(0);
        }
    }
}

 

💡개선 : 배열을 리스트로 분리했는데

동일한 버거가 있는지 돌려보고 count 배열의 숫자를 올리는게 비효율적인거 같아서

그냥 Product에 count 필드 추가해서 몇개 있는지 보고 버거 객체를 저장하는 ArrayList에 버거 객체를 저장한 후 그 객체의 count 필드의 숫자를 올리기로 함

private static ArrayList<Integer> count = new ArrayList<Integer>(Arrays.asList(0, 0, 0));
    private static ArrayList<String> name = new ArrayList<String>(Arrays.asList("Raspberry Lemonade", "Lemonade", "Fresh Brewed Iced Tea"));

    private static ArrayList<String> desc = new ArrayList<String>(Arrays.asList("쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",
            "매장에서 직접 만드는 상큼한 레몬에이드",
            "직접 유기농 홍차를 우려낸 아이스 티"));
    private static ArrayList<Double> price = new ArrayList<Double>(Arrays.asList(6.5, 6.5, 5.4));
import java.util.ArrayList;
import java.util.Arrays;

public class Drink extends Product {

    private static ArrayList<Integer> count = new ArrayList<Integer>(Arrays.asList(0, 0, 0));
    private static ArrayList<String> name = new ArrayList<String>(Arrays.asList("Raspberry Lemonade", "Lemonade", "Fresh Brewed Iced Tea"));

    private static ArrayList<String> desc = new ArrayList<String>(Arrays.asList("쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",
            "매장에서 직접 만드는 상큼한 레몬에이드",
            "직접 유기농 홍차를 우려낸 아이스 티"));
    private static ArrayList<Double> price = new ArrayList<Double>(Arrays.asList(6.5, 6.5, 5.4));

    public Drink(int select) {
        int index = select - 1;
        super.setName(name.get(index));
        super.setDesc(desc.get(index));
        super.setPrice(price.get(index));
        count.set(index, count.get(index) + 1);
    }

    public void printDescTotal() {
        int productCount = 0;
        for (int i = 0; i < name.size(); i++) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (name.get(i) == super.getName()) {
                productCount = count.get(i);
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

    public void printDesc() {
        System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
    }

    public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Drinks MENU ]\\n");
        for (int i = 0; i < count.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + name.get(i) + "   | W " + price.get(i) + " | " + desc.get(i));
        }
    }

    public static void printProductCount() {//버거별로 개수랑 같이 주문 화면에 목록 출력
        for (int i = 0; i < count.size(); i++) {//for문 돌면서 있으면 출력
            if (count.get(i) > 1) {//2개 이상이면 숫자도 출력
                System.out.println(". " + name.get(i) + "   | W " + price.get(i) + " | " + count.get(i) + " | " + desc.get(i));
            } else if (count.get(i) > 0) {
                System.out.println(". " + name.get(i) + "   | W " + price.get(i) + " | " + desc.get(i));
            }
        }
    }

    public static void clear() {
        count.clear();
    }
}

이거를 이렇게 수정하고 그 객체의 count를 쓰도록 함

Product에 id도 줌

public Drink(int select) {
        int index = select - 1;
        super.setName(name.get(index));
        super.setDesc(desc.get(index));
        super.setPrice(price.get(index));
        count.set(index, count.get(index) + 1);
    }

public Drink(int select) {
        int index = select-1;
        //id 일치하는 상품 count만 올림

        drinks.get(index).setCount(drinks.get(index).getCount()+1);
        
    }
    
    public Drink(String name, String desc, double price){//새로 생성하는 생성자
        super.setName(name);
        super.setId(drinks.size());
        super.setDesc(desc);
        super.setCount(0);
    }

생성자 두개로 나눔!

 

 

이게

private static ArrayList<Integer> count = new ArrayList<Integer>(Arrays.asList(0, 0, 0));
    private static ArrayList<String> name = new ArrayList<String>(Arrays.asList("Raspberry Lemonade", "Lemonade", "Fresh Brewed Iced Tea"));

    private static ArrayList<String> desc = new ArrayList<String>(Arrays.asList("쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",
            "매장에서 직접 만드는 상큼한 레몬에이드",
            "직접 유기농 홍차를 우려낸 아이스 티"));
    private static ArrayList<Double> price = new ArrayList<Double>(Arrays.asList(6.5, 6.5, 5.4));

이렇게 변함

private static ArrayList<Drink> drinks = new ArrayList<>(Arrays.asList((
            new Drink("Raspberry Lemonade","쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",6.5),
            new Drink("Lemonade","매장에서 직접 만드는 상큼한 레몬에이드", 6.5),
            new Drink("Fresh Brewed Iced Tea","직접 유기농 홍차를 우려낸 아이스 티",5.4)
            )
    );

 

 

이게

public void printDescTotal() {
        int productCount = 0;
        for (int i = 0; i < name.size(); i++) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (name.get(i) == super.getName()) {
                productCount = count.get(i);
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

이렇게 변함

public void printDescTotal() {
        int productCount = 0;
        for (int i = 0; i < drinks.size(); i++) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (drinks.get(i).getName() == super.getName()) {
                productCount = drinks.get(i).getCount();
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

 

 

함수 다 drinks로 변경함

public class Drink extends Product {

    private static ArrayList<Drink> drinks = new ArrayList<>(Arrays.asList((
            new Drink("Raspberry Lemonade","쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드",6.5),
            new Drink("Lemonade","매장에서 직접 만드는 상큼한 레몬에이드", 6.5),
            new Drink("Fresh Brewed Iced Tea","직접 유기농 홍차를 우려낸 아이스 티",5.4)
            )
    );

    public Drink(int select) {
        int index = select-1;
        //id 일치하는 상품 count만 올림

        drinks.get(index).setCount(drinks.get(index).getCount()+1);

    }
    public Drink(){

    }

    public Drink(String name, String desc, double price){//새로 생성하는 생성자
        super.setName(name);
        super.setId(drinks.size());
        super.setDesc(desc);
        super.setCount(0);
    }

    public void printDescTotal() {
        int productCount = 0;
        for (Drink d : drinks) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (d.getName() == super.getName()) {
                productCount = d.getCount();
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

    public void printDesc() {
        System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
    }

    public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Drinks MENU ]\\n");
        for (int i = 0; i < drinks.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + drinks.get(i).getName() + "   | W " + drinks.get(i).getPrice() + " | " + drinks.get(i).getDesc());
        }
    }

    public static void printProductCount() {//버거별로 개수랑 같이 주문 화면에 목록 출력
        for (Drink d : drinks) {//for문 돌면서 있으면 출력
            if(d.getCount()>1){//2개 이상이면 숫자도 출력
                System.out.println(". " + d.getName() + "   | W " + d.getPrice() + " | " + d.getCount() + " | " + d.getDesc());
            }else if(d.getCount()>0) {
                System.out.println(". " + d.getName() + "   | W " + d.getPrice() + " | " + d.getDesc());
            }
        }
    }

    public static void clear() {//count 비우는 함수
        for (Drink d : drinks) {//for문 돌면서 있으면 출력
            d.setCount(0);
        }
    }
}

 

 

⭐중첩 반복문 break

각 반복문마다 라벨을 지정해 주고 해당 라벨명을 break 명령에 기재하여 원하는 반복문 단계를 바로 빠져 나온다

Loop1 :
for(int i=0; i<3; i++){
   Loop2 :
   for(int j=0; j<3; j++){
      System.out.println("i="+i + " j="+j);
      if (j==1){
         break Loop1;     // end of Loop1(i)
         //break;         // end of Loop2(j)
         //break Loop2;   // end of Loop2(j)
      }
   }
}

Kioskapp에서 private인 ArrayList size를 읽어와야해서 이거 함수 추가함

public static int getSize(){
        return drinks.size();
    }
Product product;
            switch (menu) {
                case 1:
                    if ((0 < select) && (select < Burger.getSize())){
                        product = new Burger(select);
                    } else {
                        continue;
                    }
                    break;

이렇게 수정함 사이즈 변하면 자동으로 변하도록

잘 한 줄 알았는데 에러남 ㅋㅋ

private static ArrayList<Burger> burgers = new ArrayList<Burger>(Arrays.asList(
                new Burger("ShackBurger","토마토, 양상추, 쉑소스가 토핑된 치즈버거",6.9),
                new Burger("SmokeShack","베이컨, 체리 페퍼에 쉑소스가 토핑된 치즈버거", 8.9),
                new Burger("Shroom Burger","몬스터 치즈와 체다 치즈로 속을 채운 베지테리안 버거",9.4),
                new Burger("Cheeseburger","포테이토 번과 비프패티, 치즈가 토핑된 치즈버거",6.9),
                new Burger("Hamburger","비프패티를 기반으로 야채가 들어간 기본버거",5.4)
        )
        );

여기서 에러나네?

Nullpointerexception error

Arrays.asList(
                new Burger("ShackBurger","토마토, 양상추, 쉑소스가 토핑된 치즈버거",6.9),
                new Burger("SmokeShack","베이컨, 체리 페퍼에 쉑소스가 토핑된 치즈버거", 8.9),
                new Burger("Shroom Burger","몬스터 치즈와 체다 치즈로 속을 채운 베지테리안 버거",9.4),
                new Burger("Cheeseburger","포테이토 번과 비프패티, 치즈가 토핑된 치즈버거",6.9),
                new Burger("Hamburger","비프패티를 기반으로 야채가 들어간 기본버거",5.4)
        )

프로그램 시작할때 등록을 따로 해줘야할듯…

main while 들어가기 전?

main함수에서 while 들어가기 전에 이거 넣었더니 nullpointerexception은 사라짐

/*기존 메뉴 등록*/
        new Burger("ShackBurger", "토마토, 양상추, 쉑소스가 토핑된 치즈버거", 6.9);
        new Burger("SmokeShack", "베이컨, 체리 페퍼에 쉑소스가 토핑된 치즈버거", 8.9);
        new Burger("Shroom Burger", "몬스터 치즈와 체다 치즈로 속을 채운 베지테리안 버거", 9.4);
        new Burger("Cheeseburger", "포테이토 번과 비프패티, 치즈가 토핑된 치즈버거", 6.9);
        new Burger("Hamburger", "비프패티를 기반으로 야채가 들어간 기본버거", 5.4);

        new Beer("Lager", "강한 탄산감이 있는 청량한 맥주", 6.5);
        new Beer("Ale", "풍부한 향과 단맛이 나는 높은 바디감의 맥주", 6.5);
        new Beer("Abita Root Beer", "맥주인 척 하는 탄산음료", 5.4);

        new Icecream("Classic Hand-Spun Shakes", "쫀득하고 진한 커스터드가 들어간 클래식 쉐이크", 6.5);
        new Icecream("Floats", "부드러운 바닐라 커스터드와 톡톡 터지는 탄산이 만나 탄생한 색다른 음료", 6.5);
        new Icecream("Cup & Cones", "매일 점포에서 신선하게 제조하는 쫀득하고 진한 아이스크림", 5.4);

        new Drink("Raspberry Lemonade", "쉐이크쉑 시그니처 레몬에이드에 상큼 달콤한 라즈베리가 더해진 시즌 한정 레몬에이드", 6.5);
        new Drink("Lemonade", "매장에서 직접 만드는 상큼한 레몬에이드", 6.5);
        new Drink("Fresh Brewed Iced Tea", "직접 유기농 홍차를 우려낸 아이스 티", 5.4);

SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 메뉴판을 보시고 메뉴를 골라 입력해주세요. [ SHAKESHACK MENU ]

  1. Burgers | 앵거스 비프 통살을 다져만든 버거
  2. Forzen Custard | 매장에서 신선하게 만드는 아이스크림
  3. Drinks | 매장에서 직접 만드는 음료
  4. Beer | 뉴욕 브루클린 브루어리에서 양조한 맥주

[ ORDER MENU ] 5. Order | 장바구니를 확인 후 주문합니다. 6. Cancel | 진행중인 주문을 취소합니다. 7. Exit | 주문 앱에서 나갑니다. 1 → burger골랐는데요 

SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

 

🚩문제: 상품메뉴판 출력이 안 됨

 

public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Burgers MENU ]\\n");
        for (int i = 0; i < burgers.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + burgers.get(i).getName() + "   | W " + burgers.get(i).getPrice() + " | " + burgers.get(i).getDesc());
        }
    }

여기가 Drink로 되어있었고(오타) 이게 실행은 되는데 for문 돌면서가 안 나온다고 보면 될듯

public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Burgers MENU ]\\n");
        int i = 0;
        for (Burger x : burgers) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + x.getName() + "   | W " + x.getPrice() + " | " + x.getDesc());
        }
    }

이렇게 수정해봄

SHAKESHACK BURGER 에 오신걸 환영합니다.
아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Burgers MENU ]

음 이것도 안됨!!

⛳해결 : 지금보니 생성자에 burgers에다 add하는 부분이 없어서 그랬다 내 머릿속으로만 당연히 그렇게 된다고 생각하고 있었음

public Burger(String name, String desc, double price) {//새로 생성하는 생성자
        super.setName(name);
        super.setId(burgers.size());
        super.setDesc(desc);
        super.setCount(0);
        burgers.add(this);<-이거 추가함
    }

해결됨

 

 

🚩문제 : 가격이 다 0으로 뜸

아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Burgers MENU ]

  1. ShackBurger | W 0.0 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거
  2. SmokeShack | W 0.0 | 베이컨, 체리 페퍼에 쉑소스가 토핑된 치즈버거
  3. Shroom Burger | W 0.0 | 몬스터 치즈와 체다 치즈로 속을 채운 베지테리안 버거
  4. Cheeseburger | W 0.0 | 포테이토 번과 비프패티, 치즈가 토핑된 치즈버거
  5. Hamburger | W 0.0 | 비프패티를 기반으로 야채가 들어간 기본버거

⛳해결: 생성자에 price넣는 부분이 없어서 추가했다

public Drink(String name, String desc, double price){//새로 생성하는 생성자
        super.setName(name);
        super.setId(drinks.size());
        super.setDesc(desc);
        super.setCount(0);
        super.setPrice(price);<-이 부분 추가함
        drinks.add(this);
    }

[ Burgers MENU ]

  1. ShackBurger | W 6.9 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거
  2. SmokeShack | W 8.9 | 베이컨, 체리 페퍼에 쉑소스가 토핑된 치즈버거
  3. Shroom Burger | W 9.4 | 몬스터 치즈와 체다 치즈로 속을 채운 베지테리안 버거
  4. Cheeseburger | W 6.9 | 포테이토 번과 비프패티, 치즈가 토핑된 치즈버거
  5. Hamburger | W 5.4 | 비프패티를 기반으로 야채가 들어간 기본버거 1 null | W 0.0 | null 위 메뉴를 장바구니에 추가하시겠습니까?
  6. 확인 2. 취소

🚩문제 : null이 뜸

int confirm = 0;
            while (confirm == 0) {
                product.printDescTotal();//개수출력
                confirm = confirmMenu();
            }

public static int confirmMenu() {
        while (true) {

            Scanner sc = new Scanner(System.in);
            System.out.println("위 메뉴를 장바구니에 추가하시겠습니까?\\n" +
                    "1. 확인        2. 취소");
            int confirm = sc.nextInt();
            if (confirm == 1) {
                return confirm;
            } else if (confirm == 2) {
                return confirm;
            }
        }
    }

printDescTotal이 안 되고 있다

public void printDescTotal() {
        int productCount = 0;
        for (Burger x : burgers) {//for문 돌면서 이름 일치하는 상품이 2개 이상 있으면 개수 출력
            if (x.getName() == super.getName()) {
                productCount = x.getCount();
            }
        }
        if (productCount > 1) {//이름 일치하는 상품이 2개 이상이면 몇개라고 알려줌
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + productCount + " | " + super.getDesc());
        } else {//아니면 개수 빼고 출력
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }
    }

⛳해결 : 걍 1 이상이면 개수 다 출력하게 바꿀래

public void printDescTotal() {
        System.out.println(super.getName() + "     | W " + super.getPrice() + " | " +super.getCount()+ "개 | " + super.getDesc());
    }

 

 

🚩문제 :

public Drink(int select) {
        int index = select-1;
        //id 일치하는 상품 count만 올림
        drinks.get(index).setCount(drinks.get(index).getCount()+1);
    }

생성자에서 이러는거 말이 안 되는 거 같음

count만 올리는 함수 따로 만들고 그 객체 찾아서 리턴해줘야 할 거 같음.

⛳해결:

public Drink selectDrink(int select){
        int index = select-1;
        //id 일치하는 상품 count만 올림
        drinks.get(index).setCount(drinks.get(index).getCount()+1);
        return drinks.get(index);
    }

이렇게 바꿈

💡그리고 저거 수정하다가 문득 오류를 깨달았다

this를 그냥 return 했다가 결제한다 하면 this.count를 올려줘야함

confirmOrder가 실행되기 전에 new Burgers()를 저 코드로 대체해서 올리면 안 됨

해결 : 그래서 이렇게 수정했다

public Drink select(int select){
        int index = select-1;
        
        return drinks.get(index);
    }

💡set count보다 increase count decrease count 있으면 편할듯 해서 추가했다

이걸 product에만 구현하니까 편했다 상속받은 것들이 다 이 함수 쓸 수 있어서

public void increaseCount(){
        this.count = this.count+1;
    }
    public void decreaseCount(){
        this.count = this.count-1;
    }
public static Drink select(int select){
        int index = select-1;
        //id 일치하는 상품 count만 올림
        drinks.get(index).setCount(drinks.get(index).getCount()+1);
        return drinks.get(index);
    }

product = Drink.select(select);

ShackBurger | W 6.9 | 1개 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거 위 메뉴를 장바구니에 추가하시겠습니까?

  1. 확인 2. 취소

해결됨

 

아래와 같이 주문 하시겠습니까? [ Orders ]

. ShackBurger | W 6.9 | 4 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거 [ Total ] W 27.6

  1. 주문 2. 메뉴판

잘 되는듯

 

if (confirm == 1) {

                product.increaseCount();//산다 하면 물품 개수만 올려준다 동일한 이름으로 생성 x
                boolean newMenu = true;
                for (Product p : menus) {
                    if(p.getId()==product.getId()){
                        newMenu = false;
                        break;
                    }
                }
                if(newMenu == true){
                    menus.add(product);
                }
                System.out.println(product.getName() + " 가 장바구니에 추가되었습니다.");
            }

지금 객체가 되어서 같은 객체를 두 ArrayList가 같이 가리키고 있어서 product.increaseCount(); 이것만 하면 된다

menus.get(i)가 가리키는 객체랑 product가 가리키는 객체가 같아서 한 번만 increase하면 양측에 다 적용된다

System.out.println("아래와 같이 주문 하시겠습니까?\\n" +
                    "[ Orders ]\\n");
            double total = 0;
            for (Product p : menus) {
                //m.printDesc(); ->개수 출력해야 해서 바꿈
                total = total + p.getPrice()*p.getCount();
            }

개수 들어가게 가격 출력하는 부분 다 수정했다

 

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료 3 SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료 3 SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료

🚩문제 : 맥주에 문제생겨서 무한반복함

SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료 3 SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료 3 SHAKESHACK BURGER 에 오신걸 환영합니다. 아래 상품메뉴판을 보시고 상품을 골라 입력해주세요.

[ Drinks MENU ]

  1. Lager | W 6.5 | 강한 탄산감이 있는 청량한 맥주
  2. Ale | W 6.5 | 풍부한 향과 단맛이 나는 높은 바디감의 맥주
  3. Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료
case 4:
                    if ((0 < select) && (select < Beer.getSize())) {
                        product = Beer.select(select);
                    } else {
                        continue;
                    }
                    break;
                default:
                    continue;

이게 안 돌아가고 continue;만 계속 되는 상황같음

(0 < select) && (select < Beer.getSize()) -> 이게 안 돌아가는듯

3번 골랐는데.. 지금보니 getSize()가 3이라서 같거나 작음으로 바꿔줘야 할 거 같음

메뉴판에는 index+1로 나가고 있으니까

⛳해결: index수정

if ((0 < select) && (select <= Beer.getSize())) {
                        product = Beer.select(select);
                    } else {
                        continue;
                    }
                    break;

💡개선 : 근데 지금보니 printDescTotal이 바뀌어서 굳이 Beer,Drink,Burger에 따로따로 구현할 필요가 없어보임

public void printDescTotal() {
        System.out.println(super.getName() + "     | W " + super.getPrice() + " | " +super.getCount()+1+ "개 | " + super.getDesc());
    }

        public void printDesc() {
            System.out.println(super.getName() + "     | W " + super.getPrice() + " | " + super.getDesc());
        }

이거라서 그냥 Product에다 구현하고 썼다

 

🚩문제 : 가격이 0으로 나오고 갯수가 잘못 나옴

ShackBurger     | W 0.0 | 11개 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거

+this.getCount()+1+ "개 | " +

이런식으로 쓰면 그냥 String에 1이 concat되네

⛳해결:

(this.getCount()+1)

이렇게 바꿔봄

그리고 price가 Menu가 아니라 Product에 있는 거라서

super.getPrice를 this.getPrice로 바꾸었다.

해결됨

hackBurger | W 6.9 | 1개 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거 위 메뉴를 장바구니에 추가하시겠습니까?

  1. 확인 2. 취소

잘 뜬다

 

 

🚩문제: 주문은 잘 되는데 저장한 후에 꺼내면 개수대로 가격이 안 매겨진다

[ Orders ] . ShackBurger | W 6.9 | 2 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거 .

Fresh Brewed Iced Tea | W 5.4 | 직접 유기농 홍차를 우려낸 아이스 티 .

Floats | W 6.5 | 부드러운 바닐라 커스터드와 톡톡 터지는 탄산이 만나 탄생한 색다른 음료 .

Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료

[ Total ] W 31.1

[ 총 판매 목록 ]

ShackBurger | W 6.9 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거

Floats | W 6.5 | 부드러운 바닐라 커스터드와 톡톡 터지는 탄산이 만나 탄생한 색다른 음료

Fresh Brewed Iced Tea | W 5.4 | 직접 유기농 홍차를 우려낸 아이스 티

Abita Root Beer | W 5.4 | 맥주인 척 하는 탄산음료

[ Total ] W 24.200000000000003

⛳해결: getCount 안 곱하던거 해결함

else if (result == 3) {//총 판매목록
                double total = 0;
                System.out.println(
                        "[ 총 판매 목록 ]");
                for (Order o : orders) {
                    for (Product p : o.instanceMenus) {
                        //p.printDesc();
                        System.out.println(p.getName() + "     | W " + p.getPrice() + " | " + p.getDesc());
                        total = total + p.getPrice()*p.getCount();//->getCount안 곱하던거 해결함
                    }
                }
                System.out.println("[ Total ]\\nW " + total);

[ Orders ] .

ShackBurger | W 6.9 | 3 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거 .

Floats | W 6.5 | 부드러운 바닐라 커스터드와 톡톡 터지는 탄산이 만나 탄생한 색다른 음료

[ Total ]

W 27.200000000000003

[ 총 판매 목록 ]

ShackBurger | W 6.9 | 3 | 토마토, 양상추, 쉑소스가 토핑된 치즈버거

Floats | W 6.5 | 1 | 부드러운 바닐라 커스터드와 톡톡 터지는 탄산이 만나 탄생한 색다른 음료

[ Total ] W 27.200000000000003

해결되었다

 

개선 :

while (true) {
            Scanner sc = new Scanner(System.in);

            System.out.println("아래와 같이 주문 하시겠습니까?\\n" +

                    "[ Orders ]");
            double total = 0;
            for (Product p : menus) {
                //m.printDesc(); ->개수 출력해야 해서 바꿈
                total = total + p.getPrice()*p.getCount();

            }
            //개수 출력하는 함수
            Burger.printProductCount();
            Drink.printProductCount();
            Icecream.printProductCount();
            Beer.printProductCount();

예전에 이러고 있었던 거

    public static void printProductCount() {//버거별로 개수랑 같이 주문 화면에 목록 출력
        for (Burger x : burgers) {//for문 돌면서 있으면 출력
            if (x.getCount() > 1) {//2개 이상이면 숫자도 출력
                System.out.println(". " + x.getName() + "   | W " + x.getPrice() + " | " + x.getCount() + " | " + x.getDesc());
            } else if (x.getCount() > 0) {
                System.out.println(". " + x.getName() + "   | W " + x.getPrice() + " | " + x.getDesc());
            }
        }
    }

이제 menus에 count대로 들어가니까 이렇게 할 필요가 없어서 그냥 Product에다 구현함

for (Product p : menus) {
                total = total + p.getPrice()*p.getCount();

            }
            //개수 출력하는 함수
            Burger.printProductCount();
            Drink.printProductCount();
            Icecream.printProductCount();
            Beer.printProductCount();

원래 이러고 있었는데

for (Product p : menus) {
                p.printDescTotal();
                total = total + p.getPrice()*p.getCount();

            }

이렇게 바꿈

그리고 돌아가서 주문을 생성했는데 그냥 여기서 함

for (Product m : menus) {

                    Product product = new Product(m.getName(), m.getDesc(), m.getPrice(), m.getCount());
                    Order order = new Order();
                    order.instanceMenus = new ArrayList<Product>();
                    order.instanceMenus.add(product);
                    orders.add(order);
                }
                menus.clear();//static 메뉴선택 끝나서 장바구니 비워줌
                /*개수 카운트 비워줌*/
                Burger.clear();
                Drink.clear();
                Icecream.clear();
                Beer.clear();
if (x == 1) {//주문
                increaseWaiting();//대기 인원 증가
                System.out.println("주문이 완료되었습니다!\\n\\n" +
                        "대기번호는 [ " + getWaiting() + " ] 번 입니다.\\n" +
                        "(3초후 메뉴판으로 돌아갑니다.)");
                
                //3초 기다려야됨

                return x;
if (x == 1) {//주문
                increaseWaiting();//대기 인원 증가
                for (Product m : menus) {
                    Product product = new Product(m.getName(), m.getDesc(), m.getPrice(), m.getCount());
                    Order order = new Order();
                    order.instanceMenus = new ArrayList<Product>();
                    order.instanceMenus.add(product);
                    order.setTotal(total);
                    orders.add(order);
                }
                menus.clear();//static 메뉴선택 끝나서 장바구니 비워줌
                /*개수 카운트 비워줌*/
                Burger.clear();
                Drink.clear();
                Icecream.clear();
                Beer.clear();

                System.out.println("주문이 완료되었습니다!\\n\\n" +
                        "대기번호는 [ " + getWaiting() + " ] 번 입니다.\\n" +
                        "(3초후 메뉴판으로 돌아갑니다.)");
                //3초 기다려야됨
                return x;

그냥 이렇게 수정함

돌아가서 orders에 넣지 않고 그냥 주문이 완료된 그 시점에서 바로 추가되게 함

이렇게 있고 이렇게 쓰던 거 그냥 Product에 인덱스 붙어서 출력되는 버전으로 바꿔버림

public static void printProduct() {//메뉴 선택시 출력
        System.out.println("[ Beer MENU ]");
        for (int i = 0; i < beers.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " + beers.get(i).getName() + "   | W " + beers.get(i).getPrice() + " | " + beers.get(i).getDesc());
        }
    }

이렇게 각각 구현되어 있대

public static void printIndex(ArrayList<Product> p) {
        for (int i = 0; i < p.size(); i++) {//for문 돌면서 있으면 출력
            System.out.println((i + 1) + ". " +p.get(i).getName() + "   | W " + p.get(i).getPrice() + " | " + p.get(i).getDesc());
        }
    }

그냥 이렇게 상위클래스에다 합침

기존 name은 productName으로 쓰고 menuname을 새로 만드는게 좋겠음

case 1:
                    System.out.println("[ Burger MENU ]");
                    Product.printIndex(Burger.burgers);
                    break;

이렇게 개선함

public class Burger extends Product {

    public static ArrayList<Product> burgers = new ArrayList<Product>();

    public static Product select(int select){
        int index = select-1;
        return burgers.get(index);
    }

    public Burger(String name, String desc, double price) {//새로 생성하는 생성자
        super.setName(name);
        super.setId("burger"+burgers.size());
        super.setDesc(desc);
        super.setCount(0);
        super.setPrice(price);
        burgers.add(this);
    }

    public static void clear() {//count 비우는 함수
        for (Product x : burgers) {//for문 돌면서 있으면 출력
            x.setCount(0);
        }
    }

    public static int getSize() {
        return burgers.size();
    }
}

그리고 버거의 모든 버거를 Product로 대체함, 생성자는 내일 고치고 저 배열을 Product에 넣어야겠음

burgers로 명명 x 이름 없이 그냥 size와 index로 다 돌아가는걸 만들어야겠음