[Project] Java - ํ‚ค์˜ค์Šคํฌ ๐Ÿ› 

๊น€์ƒ์—ฝยท2024๋…„ 1์›” 5์ผ
0

Project

๋ชฉ๋ก ๋ณด๊ธฐ
1/9
post-thumbnail

JAVA ํ‚ค์˜ค์Šคํฌ ๊ตฌํ˜„์‹ค์Šต

์‹ค์Šต ์†Œ๊ฐœ

๐Ÿ“ข ๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š” ์นดํŽ˜ ๋˜๋Š” ํŒจ์ŠคํŠธํ‘ธ๋“œ์ ์˜ ํ‚ค์˜ค์Šคํฌ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž!

  • ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์›Œ์˜จ Java ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ‚ค์˜ค์Šคํฌ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค.
  • ๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š” ์นดํŽ˜๋‚˜ ํŒจ์ŠคํŠธํ‘ธ๋“œ์ ์˜ ๋ฉ”๋‰ดํŒ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์žฌ๋ฐŒ๊ฒ ์ฃ ?

ํ•„์ˆ˜ ์š”๊ตฌ์‚ฌํ•ญ

  1. ๋ฉ”์ธ ๋ฉ”๋‰ดํŒ ํ™”๋ฉด
    • ๋ฉ”์ธ ๋ฉ”๋‰ดํŒ์ด ์ถœ๋ ฅ๋˜๋ฉฐ ๋ฉ”๋‰ดํŒ์—๋Š” ์ƒํ’ˆ ๋ฉ”๋‰ด๊ฐ€ ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.
    • ์ƒํ’ˆ ๋ฉ”๋‰ด๋Š” ๊ฐ„๋‹จํ•œ ์„ค๋ช…๊ณผ ํ•จ๊ป˜ ์ถœ๋ ฅ ๋˜๋ฉฐ ์ตœ์†Œ 3๊ฐœ ์ด์ƒ ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.
    • ์ƒํ’ˆ ๋ฉ”๋‰ด ์•„๋ž˜์—๋Š” Order(์ฃผ๋ฌธ)์™€ Cancel(์ฃผ๋ฌธ ์ทจ์†Œ) ์˜ต์…˜์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.
  2. ์ƒํ’ˆ ๋ฉ”๋‰ดํŒ ํ™”๋ฉด
    • ์ƒํ’ˆ ๋ฉ”๋‰ด ์„ ํƒ ์‹œ ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋ฉ”๋‰ดํŒ์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.
    • ๋ฉ”๋‰ดํŒ์—๋Š” ๊ฐ ๋ฉ”๋‰ด์˜ ์ด๋ฆ„๊ณผ ๊ฐ€๊ฒฉ๊ณผ ๊ฐ„๋‹จํ•œ ์„ค๋ช…์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
  3. ๊ตฌ๋งค ํ™”๋ฉด
    • ์ƒํ’ˆ ์„ ํƒ ์‹œ ํ•ด๋‹น ์ƒํ’ˆ์„ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€ํ• ์ง€ ํ™•์ธํ•˜๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.
    • 1.ํ™•์ธ ์ž…๋ ฅ ์‹œ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€๋˜์—ˆ๋‹ค๋Š” ์•ˆ๋‚ด ๋ฌธ๊ตฌ์™€ ํ•จ๊ป˜ ๋ฉ”์ธ ๋ฉ”๋‰ด๋กœ ๋‹ค์‹œ ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.
  4. ์ฃผ๋ฌธ ํ™”๋ฉด
    • 5.Order ์ž…๋ ฅ ์‹œ ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.
    • ์žฅ๋ฐ”๊ตฌ๋‹ˆ์—์„œ๋Š” ์ถ”๊ฐ€๋œ ๋ฉ”๋‰ด๋“ค๊ณผ ์ด ๊ฐ€๊ฒฉ์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.
    • 1.์ฃผ๋ฌธ ์ž…๋ ฅ ์‹œ ์ฃผ๋ฌธ์™„๋ฃŒ ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐ€๊ณ , 2.๋ฉ”๋‰ดํŒ ์ž…๋ ฅ ์‹œ ๋‹ค์‹œ ๋ฉ”์ธ ๋ฉ”๋‰ด๋กœ ๋Œ์•„์˜ต๋‹ˆ๋‹ค.
  5. ์ฃผ๋ฌธ์™„๋ฃŒ ํ™”๋ฉด
    • 1.์ฃผ๋ฌธ ์ž…๋ ฅ ์‹œ ๋Œ€๊ธฐ๋ฒˆํ˜ธ๋ฅผ ๋ฐœ๊ธ‰ํ•ด์ค๋‹ˆ๋‹ค.
    • ์žฅ๋ฐ”๊ตฌ๋‹ˆ๋Š” ์ดˆ๊ธฐํ™”๋˜๊ณ  3์ดˆ ํ›„์— ๋ฉ”์ธ ๋ฉ”๋‰ดํŒ์œผ๋กœ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค.
  6. ์ฃผ๋ฌธ ์ทจ์†Œ ํ™”๋ฉด
    • ๋ฉ”๋‰ดํŒ์—์„œ 6.Cancel ์ž…๋ ฅ์‹œ ์ฃผ๋ฌธ์„ ์ทจ์†Œํ• ์ง€ ํ™•์ธ์„ ์š”์ฒญํ•˜๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.
    • 1.ํ™•์ธ ์„ ์ž…๋ ฅํ•˜๋ฉด ์žฅ๋ฐ”๊ตฌ๋‹ˆ๋Š” ์ดˆ๊ธฐํ™”๋˜๊ณ  ์ทจ์†Œ ์™„๋ฃŒ ๋ฌธ๊ตฌ์™€ ํ•จ๊ป˜ ๋ฉ”๋‰ดํŒ์ด ์ถœ๋ ฅ ๋ฉ๋‹ˆ๋‹ค.

์„ ํƒ ์š”๊ตฌ์‚ฌํ•ญ

  1. ์ฃผ๋ฌธ ๊ฐœ์ˆ˜ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋˜‘๊ฐ™์€ ์ƒํ’ˆ์ด ๋‹ด๊ธฐ๋ฉด ์ฃผ๋ฌธ ํ™”๋ฉด์—์„œ ์ƒํ’ˆ ๊ฐœ์ˆ˜๊ฐ€ ์ถœ๋ ฅ ๋˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  2. ์ƒํ’ˆ ์˜ต์…˜ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ์ƒํ’ˆ์— ์˜ต์…˜์„ ์„ ํƒ ํ›„ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ธ๋ถ„ํ™” ํ•ฉ๋‹ˆ๋‹ค.
  3. ์ด ํŒ๋งค๊ธˆ์•ก ์กฐํšŒ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ๊ตฌ๋งค๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๋งˆ๋‹ค ์ด ํŒ๋งค ๊ธˆ์•ก์„ ๋ˆ„์ ํ•ด์ค๋‹ˆ๋‹ค.
    • ์ˆจ๊ฒจ์ง„ ๊ธฐ๋Šฅ์œผ๋กœ 0๋ฒˆ ์ž…๋ ฅ ์‹œ ์ด ํŒ๋งค๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  4. ์ด ํŒ๋งค์ƒํ’ˆ ๋ชฉ๋ก ์กฐํšŒ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ๊ตฌ๋งค๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๋งˆ๋‹ค ํŒ๋งค ์ƒํ’ˆ ๋ชฉ๋ก์„ ์ €์žฅํ•ด์ค๋‹ˆ๋‹ค.
    • ์ˆจ๊ฒจ์ง„ ๊ธฐ๋Šฅ์œผ๋กœ 0๋ฒˆ ์ž…๋ ฅ ์‹œ ์ด ํŒ๋งค ์ƒํ’ˆ ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

ํด๋ž˜์Šค ๋‹ค์ด์–ด๊ทธ๋žจ

Main : KioskService ํด๋ž˜์Šค๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ฉ”์ธํด๋ž˜์Šค
KioskService : ๋ฉ”๋‰ดํŒ ๋ชฉ๋ก์„ ๋กœ๋“œ(initMenu)ํ•˜๊ณ , ํ™”๋ฉด์ถœ๋ ฅ๊ณผ ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ƒํ™ฉ์— ๋งž๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์•กํ‹ฐ๋ธŒ ํด๋ž˜์Šค
Menu : ๋ฒ„๊ฑฐ๋ฅ˜, ์Œ๋ฃŒ๋ฅ˜ ๋“ฑ ์นดํ…Œ๊ณ ๋ฆฌ๋ฉ”๋‰ด๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๋ฉ”๋‰ด ํด๋ž˜์Šค
Product : Menu ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š” ์ž์‹ ํด๋ž˜์Šค. @@๋ฒ„๊ฑฐ, @@์Œ๋ฃŒ ๋“ฑ ์นดํ…Œ๊ณ ๋ฆฌ ๋‚ด ๋“ค์–ด๊ฐˆ ์ƒํ’ˆ์˜ ์„ค๊ณ„๋„
Order : ์ฃผ๋ฌธ ์ฒ˜๋ฆฌ, ์ฃผ๋ฌธ ์ทจ์†Œ, ์ด ํŒ๋งค๋ชฉ๋ก, ์ด ํŒ๋งค๊ธˆ์•ก ๋“ฑ ์ฃผ๋ฌธ๊ณผ ๊ด€๋ จ๋œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํด๋ž˜์Šค

1. Main.java

  • kiosk๋ฅผ ์„ ์–ธํ•˜๊ณ , ๋ฉ”๋‰ดํŒ ๋ชฉ๋ก์„ ๋กœ๋“œ ๋ฐ ํ™”๋ฉด์ถœ๋ ฅ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ
public class Main {
    public static void main(String[] args) throws InterruptedException {
        KioskService kiosk = new KioskService();
        kiosk.initMenu();
        kiosk.mainMenu();
    }
}

2. Menu.java

  • ์ด๋ฆ„๊ณผ ์„ค๋ช… ํ•„๋“œ๋ฅผ ๊ฐ€์ง€๋Š” ํด๋ž˜์Šค๋กœ ์ž‘์„ฑ
  • ๋ณ€์ˆ˜๋ฅผ private์„ ์–ธํ•˜๋˜, ๊ฐ’์„ ํ•„์š”๋กœ ํ•  ๊ฒฝ์šฐ getter์„ ํ†ตํ•œ ํ•„๋“œ ์ ‘๊ทผ
  • show() : ๊ณตํ†ต๋œ ์ถœ๋ ฅ๋ฐฉ๋ฒ•์„ show() ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“  ๋ฉ”์„œ๋“œ
public class Menu {
    private String name;
    private String description;

    public Menu(String name, String description){
        this.name = name;
        this.description = description;
    }

    public String getName(){
        return name;
    }

    public String getDescription(){
        return description;
    }

    public void show(){
        System.out.printf("%-20s | %s\n", name, description);
    }
}

3. Product.java

  • ์ด๋ฆ„, ๊ฐ€๊ฒฉ, ์„ค๋ช… ํ•„๋“œ๋ฅผ ๊ฐ€์ง€๋Š” ํด๋ž˜์Šค
  • ์นดํ…Œ๊ณ ๋ฆฌ ์‹๋ณ„์„ ์œ„ํ•œ ์นดํ…Œ๊ณ ๋ฆฌ ํ•„๋“œ, ์‚ฌ์ด์ฆˆ์—… ์˜ต์…˜ ์ถ”๊ฐ€๋ฅผ ์œ„ํ•œ ์‚ฌ์ด์ฆˆ์—… ๊ฐ€๊ฒฉ ํ•„๋“œ ์ถ”๊ฐ€
  • ๋ถ€๋ชจ ๋ฉ”์„œ๋“œ show()๋ฅผ ๊ฐ€๊ฒฉ์„ ์ถœ๋ ฅํ•˜๋„๋ก ์˜ค๋ฒ„๋ผ์ด๋“œ
  • ๋ณ€์ˆ˜๋ฅผ private์„ ์–ธํ•˜๋˜, ๊ฐ’์„ ํ•„์š”๋กœ ํ•  ๊ฒฝ์šฐ getter์„ ํ†ตํ•œ ํ•„๋“œ ์ ‘๊ทผ
public class Product extends Menu{

    private double price;
    private double sizeupPrice;
    private String category;

    public Product(String name, String description, double price, String category){
        super(name, description);
        this.price = price;
        this.category = category;
        this.sizeupPrice = 0;
    }

    public Product(String name, String description, double price, double sizeupPrice, String category){
        super(name, description);
        this.price = price;
        this.category = category;
        this.sizeupPrice = sizeupPrice;
    }

    public double getPrice(){
        return price;
    }

    public double getSizeupPrice(){
        return sizeupPrice;
    }

    public String getCategory(){
        return category;
    }

    public void show(){
        System.out.printf("%-20s | W %s |%s\n", getName(), price,getDescription());
    }
}

4. Order.java

  • ์ฃผ๋ฌธ๊ด€๋ จ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํด๋ž˜์Šค
  • ๋ณ€์ˆ˜๋ฅผ private์„ ์–ธํ•˜๋˜, ๊ฐ’์„ ํ•„์š”๋กœ ํ•  ๊ฒฝ์šฐ getter์„ ํ†ตํ•œ ํ•„๋“œ ์ ‘๊ทผ
  • addorder(Product product) : ์ฃผ๋ฌธ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์žฅ๋ฐ”๊ตฌ๋‹ˆ(shoppingbag)์— ์ €์žฅ
  • addorder(Product product, double sizeupPrice) : ์‚ฌ์ด์ฆˆ์—…์ด ๊ฐ€๋Šฅํ•œ ๋ฉ”๋‰ด์ผ ๊ฒฝ์šฐ ์‚ฌ์ด์ฆˆ์—… ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ €์žฅ
  • cancelorder() : ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋น„์šฐ๊ธฐ
  • show() : ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์žˆ๋Š” ์ฃผ๋ฌธ์„ ์ •๋ ฌํ•˜๊ณ , ๊ฐ™์€ ์ฃผ๋ฌธ์˜ ๊ฐœ์ˆ˜๋ฅผ ํŒŒ์•…ํ•˜์—ฌ ์ถœ๋ ฅ
  • sold() : ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์žˆ๋Š” ์ฃผ๋ฌธ์„ ํŒ๋งค๋ชฉ๋ก(sold)์— ์ €์žฅ
  • soldprint() : ํŒ๋งค๋ชฉ๋ก์— ์žˆ๋Š” ์ฃผ๋ฌธ์„ ์ •๋ ฌํ•˜๊ณ , ๊ฐ™์€ ์ฃผ๋ฌธ์˜ ๊ฐœ์ˆ˜๋ฅผ ํŒŒ์•…ํ•˜์—ฌ ์ถœ๋ ฅ
  • total() : ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์žˆ๋Š” ์ฃผ๋ฌธ์˜ ์ด ๊ธˆ์•ก์„ ์ถœ๋ ฅ
public class Order {
    private ArrayList<Product> shoppingbag = new ArrayList<Product>();
    private ArrayList<Product> sold = new ArrayList<Product>();
    private double totalprice;
    public void addorder(Product product){
        int yesno;
        Scanner sc = new Scanner(System.in);
        do {
            clearScreen();
            product.show();
            System.out.println("์œ„ ๋ฉ”๋‰ด๋ฅผ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n");
            System.out.println("1. ํ™•์ธ        2. ์ทจ์†Œ\n");
            yesno = sc.nextInt();
            if(yesno==1) {
                clearScreen();
                shoppingbag.add(product);
                System.out.printf("%s ๊ฐ€ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.\n\n", product.getName());
            }
            else if(yesno==2){
                clearScreen();
            }
        }while(yesno < 1 || yesno > 2);
    }

    public void addorder(Product product, double sizeupPrice){
        int yesno;
        Scanner sc = new Scanner(System.in);
        String name = product.getName() + " (Sizeup)";
        Product sizeUpProduct = new Product(name,product.getDescription(),product.getSizeupPrice(),product.getCategory());
        do {
            clearScreen();
        sizeUpProduct.show();
        System.out.println("์œ„ ๋ฉ”๋‰ด๋ฅผ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n");
        System.out.println("1. ํ™•์ธ        2. ์ทจ์†Œ\n");
        yesno = sc.nextInt();
            if(yesno==1) {
                clearScreen();
                shoppingbag.add(sizeUpProduct);
                System.out.printf("%s ๊ฐ€ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.\n\n", sizeUpProduct.getName());
            }
            else if(yesno==2){
                clearScreen();
            }
        }while(yesno < 1 || yesno > 2);
    }
    
    public void cancelorder(){
        shoppingbag.clear();
    }

    public void show(){
        Collections.sort(shoppingbag, new Comparator<Product>() {
            @Override
            public int compare(Product o1, Product o2) {
                if(o1.getName().compareTo(o2.getName())>0) return 1;
                if(o1.getName().compareTo(o2.getName())<0) return -1;
                return 0;
            }
        });
        int ea = 1;
        for(int i=0; i<shoppingbag.size()-1;i++){
            if(shoppingbag.get(i).getName().equals(shoppingbag.get(i+1).getName()))
                ea++;
            else {
                System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", shoppingbag.get(i).getName(), shoppingbag.get(i).getPrice(),ea, shoppingbag.get(i).getDescription());
                ea=1;
            }
        }
        if(ea!=1&&shoppingbag.size()>1)
            System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", shoppingbag.get(shoppingbag.size()-2).getName(), shoppingbag.get(shoppingbag.size()-2).getPrice(),ea, shoppingbag.get(shoppingbag.size()-2).getDescription());
        else if(ea==1&&shoppingbag.size()>0)
            System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", shoppingbag.get(shoppingbag.size()-1).getName(), shoppingbag.get(shoppingbag.size()-1).getPrice(),ea, shoppingbag.get(shoppingbag.size()-1).getDescription());

    }

    public void sold(){
        for(Product cart : shoppingbag)
            sold.add(cart);
    }

    public void soldprint(){
        Collections.sort(sold, new Comparator<Product>() {
            @Override
            public int compare(Product o1, Product o2) {
                if(o1.getName().compareTo(o2.getName())>0) return 1;
                if(o1.getName().compareTo(o2.getName())<0) return -1;
                return 0;
            }
        });
        int ea = 1;
        for(int i=0; i<sold.size()-1;i++){
            if(sold.get(i).getName().equals(sold.get(i+1).getName()))
                ea++;
            else {
                System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", sold.get(i).getName(), sold.get(i).getPrice(),ea, sold.get(i).getDescription());
                ea=1;
            }
        }
        if(ea!=1)
            System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", sold.get(sold.size()-2).getName(), sold.get(sold.size()-2).getPrice(),ea, sold.get(sold.size()-2).getDescription());
        else if(ea==1)
            System.out.printf("%-20s | W %s | %d๊ฐœ | %s\n", sold.get(sold.size()-1).getName(), sold.get(sold.size()-1).getPrice(),ea, sold.get(sold.size()-1).getDescription());
    }
    
    public void total(){
        totalprice = 0;
        for(Product cart : shoppingbag)
            totalprice += cart.getPrice();
        System.out.println("[ Total ]");
        System.out.printf("W %s \n",Math.round(totalprice*10)/10.0);
    }

    public double getTotalPrice(){return totalprice;}

}

5. KioskService.java

  • initMenu() : ์นดํ…Œ๊ณ ๋ฆฌ ๋ฉ”๋‰ด, ์ „์ฒด์ƒํ’ˆ ๋ฉ”๋‰ด๋ฅผ ArrayList์— ์ €์žฅํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • mainMenu() : ํ™”๋ฉด์„ ์ถœ๋ ฅํ•˜๊ณ , ์‚ฌ์šฉ์ž ์‘๋‹ต์„ ๋ฐ›๋Š” ๋ฉ”์„œ๋“œ
  • sellMenu() : ํŒ๋งค๋œ ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•˜๊ณ , ์‚ฌ์šฉ์ž ์‘๋‹ต์„ ๋ฐ›๋Š” ๋ฉ”์„œ๋“œ
  • categoryMenu() : ์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ ๋ฉ”๋‰ดํŒ์„ ์ถœ๋ ฅํ•˜๊ณ , ์‚ฌ์šฉ์ž ์‘๋‹ต์„ ๋ฐ›๋Š” ๋ฉ”์„œ๋“œ
  • orderMenu() : ์ฃผ๋ฌธ ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•˜๊ณ , ์‚ฌ์šฉ์ž ์‘๋‹ต์„ ๋ฐ›๋Š” ๋ฉ”์„œ๋“œ
  • cancelMenu() : ์‚ฌ์šฉ์ž ์‘๋‹ต์„ ๋ฐ›์•„ ์ฃผ๋ฌธ ๋ชฉ๋ก์„ ์‚ญ์ œํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • clearScreen() : ํ™”๋ฉด ์ „ํ™˜์„ ํ•˜๋Š” ๋ฉ”์„œ๋“œ
public class KioskService {
    private Order order = new Order();
    private ArrayList<Menu> category = new ArrayList<Menu>();
    private ArrayList<Product> product = new ArrayList<Product>();
    private ArrayList<Product> categoryProduct = new ArrayList<Product>();
    private int count = 1;
    private double sell;
    public void initMenu() {

        Menu burgers = new Menu("Burgers", "์•ต๊ฑฐ์Šค ๋น„ํ”„ ํ†ต์‚ด์„ ๋‹ค์ ธ๋งŒ๋“  ๋ฒ„๊ฑฐ");
        Menu frozencustard = new Menu("Frozen Custard", "๋งค์žฅ์—์„œ ์‹ ์„ ํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ์•„์ด์Šคํฌ๋ฆผ");
        Menu drinks = new Menu("Drinks", "๋งค์žฅ์—์„œ ์ง์ ‘ ๋งŒ๋“œ๋Š” ์Œ๋ฃŒ");
        Menu beer = new Menu("Beer", "๋‰ด์š• ๋ธŒ๋ฃจํด๋ฆฐ ๋ธŒ๋ฃจ์–ด๋ฆฌ์—์„œ ์–‘์กฐํ•œ ๋งฅ์ฃผ");
        category.add(burgers);
        category.add(frozencustard);
        category.add(drinks);
        category.add(beer);

        Product shackburger = new Product("ShackBurger", "ํ† ๋งˆํ† , ์–‘์ƒ์ถ”, ์‰‘์†Œ์Šค๊ฐ€ ํ† ํ•‘๋œ ์น˜์ฆˆ๋ฒ„๊ฑฐ", 6.9, 10.9, "Burgers");
        Product smokeshack = new Product("SmokeShack", "๋ฒ ์ด์ปจ, ์ฒด๋ฆฌ ํŽ˜ํผ์— ์‰‘์†Œ์Šค๊ฐ€ ํ† ํ•‘๋œ ์น˜์ฆˆ๋ฒ„๊ฑฐ", 8.9, 12.9, "Burgers");
        Product shroomburger = new Product("Shroom Burger", "๋ชฌ์Šคํ„ฐ ์น˜์ฆˆ์™€ ์ฒด๋‹ค ์น˜์ฆˆ๋กœ ์†์„ ์ฑ„์šด ๋ฒ ์ง€ํ…Œ๋ฆฌ์•ˆ ๋ฒ„๊ฑฐ", 9.4, "Burgers");
        Product cheeseburger = new Product("Cheeseburger", "ํฌํ…Œ์ดํ†  ๋ฒˆ๊ณผ ๋น„ํ”„ํŒจํ‹ฐ, ์น˜์ฆˆ๊ฐ€ ํ† ํ•‘๋œ ์น˜์ฆˆ๋ฒ„๊ฑฐ", 6.9, 10.9, "Burgers");
        Product hamburger = new Product("Hamburger", "๋น„ํ”„ํŒจํ‹ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์•ผ์ฑ„๊ฐ€ ๋“ค์–ด๊ฐ„ ๊ธฐ๋ณธ๋ฒ„๊ฑฐ", 6.9, 9.0, "Burgers");
        product.add(shackburger);
        product.add(smokeshack);
        product.add(shroomburger);
        product.add(cheeseburger);
        product.add(hamburger);

        Product shakes = new Product("Shakes", "๋ฐ”๋‹๋ผ, ์ดˆ์ฝœ๋ ›, ์†”ํ‹ฐ๋“œ ์นด๋ผ๋ฉœ, ๋ธ”๋ž™ & ํ™”์ดํŠธ, ์ŠคํŠธ๋กœ๋ฒ ๋ฆฌ, ํ”ผ๋„› ๋ฒ„ํ„ฐ, ์ปคํ”ผ", 5.9, "Frozen Custard");
        Product shakeoftheweek = new Product("Shake of the Week", "ํŠน๋ณ„ํ•œ ์ปค์Šคํ„ฐ๋“œ ํ”Œ๋ ˆ์ด๋ฒ„", 6.5, "Frozen Custard");
        Product redbeanshake = new Product("Red Bean Shake", "์‹ ์„ ํ•œ ์ปค์Šคํ„ฐ๋“œ์™€ ํ•จ๊ป˜ ์šฐ์œ ์™€ ๋ ˆ๋“œ๋นˆ์ด ๋ธ”๋ Œ๋”ฉ ๋œ ์‹œ์ฆˆ๋„ ์‰์ดํฌ", 6.5, "Frozen Custard");
        Product floats = new Product("Floats", "๋ฃจํŠธ ๋น„์–ด, ํผํ”Œ ์นด์šฐ, ํฌ๋ฆผ ์‹œํด", 5.9, "Frozen Custard");
        Product cupsandcones = new Product("Cups & Cones", "๋ฐ”๋‹๋ผ, ์ดˆ์ฝœ๋ ›, Flavor of the Week", 4.9, 5.9, "Frozen Custard");
        Product concretes = new Product("Concretes", "์‰์ดํฌ์‰‘์˜ ์ซ€๋“ํ•œ ์ปค์Šคํ„ฐ๋“œ์™€ ๋‹ค์–‘ํ•œ ๋ฏน์Šค-์ธ์˜ ์กฐํ•ฉ", 5.9, 8.9, "Frozen Custard");
        Product shackattack = new Product("Shack Attack", "์ดˆ์ฝœ๋ › ํผ์ง€์†Œ์Šค, ์ดˆ์ฝœ๋ › ํŠธ๋Ÿฌํ”Œ ์ฟ ํ‚ค, Lumiere ์ดˆ์ฝœ๋ › ์ฒญํฌ์™€ ์Šคํ”„๋งํด์ด ๋“ค์–ด๊ฐ„ ์ง„ํ•œ ์ดˆ์ฝœ๋ › ์ปค์Šคํ„ฐ๋“œ", 5.9, "Frozen Custard");
        product.add(shakes);
        product.add(shakeoftheweek);
        product.add(redbeanshake);
        product.add(floats);
        product.add(cupsandcones);
        product.add(concretes);
        product.add(shackattack);

        Product shackmadelemonade = new Product("Shack-made Lemonade", "๋งค์žฅ์—์„œ ์ง์ ‘ ๋งŒ๋“œ๋Š” ์ƒํผํ•œ ๋ ˆ๋ชฌ์—์ด๋“œ(์˜ค๋ฆฌ์ง€๋‚ /์‹œ์ฆˆ๋„)", 3.9, "Drinks");
        Product freshbrewedicedtea = new Product("Fresh Brewed Iced Tea", "์ง์ ‘ ์œ ๊ธฐ๋† ํ™์ฐจ๋ฅผ ์šฐ๋ ค๋‚ธ ์•„์ด์Šคํ‹ฐ", 3.4, "Drinks");
        Product fiftyfifty = new Product("Fifty/Fifty", "๋ ˆ๋ชฌ์—์ด๋“œ์™€ ์•„์ด์Šคํ‹ฐ์˜ ๋งŒ๋‚จ", 3.5, "Drinks");
        Product fountainsoda = new Product("Fountain Soda", "์ฝ”์นด์ฝœ๋ผ, ์ฝ”์นด์ฝœ๋ผ ์ œ๋กœ, ์Šคํ”„๋ผ์ดํŠธ, ํ™˜ํƒ€ ์˜ค๋ Œ์ง€, ํ™˜ํƒ€ ๊ทธ๋ ˆ์ดํ”„", 2.7, "Drinks");
        Product abitarootbeer = new Product("Abita Root Beer", "์ฒญ๋Ÿ‰๊ฐ ์žˆ๋Š” ๋…ํŠนํ•œ ๋ฏธ๊ตญ์‹ ๋ฌด์•Œ์ฝœ ํƒ„์‚ฐ์Œ๋ฃŒ", 4.4, "Drinks");
        Product bottledwater = new Product("Bottled Water", "์ง€๋ฆฌ์‚ฐ ์•”๋ฐ˜๋Œ€์ˆ˜์ธต์œผ๋กœ ๋งŒ๋“  ํ”„๋ฆฌ๋ฏธ์—„ ์ƒ์ˆ˜", 1.0, "Drinks");
        product.add(shackmadelemonade);
        product.add(freshbrewedicedtea);
        product.add(fiftyfifty);
        product.add(fountainsoda);
        product.add(abitarootbeer);
        product.add(bottledwater);

        Product shackmeisterale = new Product("ShackMeister Ale", "์‰์ดํฌ์‰‘ ๋ฒ„๊ฑฐ๋ฅผ ์œ„ํ•ด ๋‰ด์š• ๋ธŒ๋ฃจํด๋ฆฐ ๋ธŒ๋ฃจ์–ด๋ฆฌ์—์„œ ํŠน๋ณ„ํžˆ ์–‘์กฐํ•œ ์—์ผ ๋งฅ์ฃผ", 9.8, "Beer");
        Product magpiebrewingco = new Product("Magpie Brewing Co.", "์„ค๋ช… ์—†์Œ", 6.8, "Beer");
        product.add(shackmeisterale);
        product.add(magpiebrewingco);
    }


    public void mainMenu() throws InterruptedException {
        while (true) {
            Scanner sc = new Scanner(System.in);
            int input = 0;
            int number = 0;
            System.out.println("\"SHAKESHACK BURGER ์— ์˜ค์‹ ๊ฑธ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.\"");
            System.out.println("์•„๋ž˜ ๋ฉ”๋‰ดํŒ์„ ๋ณด์‹œ๊ณ  ๋ฉ”๋‰ด๋ฅผ ๊ณจ๋ผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n");
            System.out.println("[ SHAKESHACK MENU ]");
            for (Menu menu : category) {
                number++;
                System.out.printf("%d. ", number);
                menu.show();
            }
            System.out.println("\n[ ORDER MENU ]");
            System.out.println("5. Order       | ์žฅ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ํ™•์ธ ํ›„ ์ฃผ๋ฌธํ•ฉ๋‹ˆ๋‹ค.");
            System.out.println("6. Cancel      | ์ง„ํ–‰์ค‘์ธ ์ฃผ๋ฌธ์„ ์ทจ์†Œํ•ฉ๋‹ˆ๋‹ค.");
            input = sc.nextInt();
            switch(input){
                case 0:
                    sellMenu();
                    break;

                case 1: case 2: case 3: case 4:
                    categoryMenu(input, category.get(input - 1).getName());
                    break;

                case 5:
                    orderMenu();
                    break;

                case 6:
                    cancelMenu();
                    break;
            }
        }
    }

    public void sellMenu(){
        int yesno;
        Scanner sc = new Scanner(System.in);
        do {
            clearScreen();

            System.out.println("[ ์ด ํŒ๋งค์ƒํ’ˆ ๋ชฉ๋ก ํ˜„ํ™ฉ ]");
            System.out.println("ํ˜„์žฌ๊นŒ์ง€ ์ด ํŒ๋งค๋œ ์ƒํ’ˆ ๋ชฉ๋ก์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.");
            order.soldprint();
            System.out.printf("ํ˜„์žฌ๊นŒ์ง€ ์ด ํŒ๋งค๋œ ๊ธˆ์•ก์€ [ W  %s  ] ์ž…๋‹ˆ๋‹ค.\n\n",Math.round(sell*10)/10.0);
            System.out.println("1. ๋Œ์•„๊ฐ€๊ธฐ\n");
            yesno = sc.nextInt();
        }while(yesno!=1);
        clearScreen();
    }
    public void categoryMenu(int number, String category) throws InterruptedException {
        int input;
        int yesNo;
        int i = 0;
        Scanner sc = new Scanner(System.in);
        if (0 < number && number < 5) { //product
            do {
                i = 0;
                categoryProduct.clear();
                clearScreen();
                System.out.println("\"SHAKESHACK BURGER ์— ์˜ค์‹ ๊ฑธ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.\"");
                System.out.println("์•„๋ž˜ ์ƒํ’ˆ๋ฉ”๋‰ดํŒ์„ ๋ณด์‹œ๊ณ  ๋ฉ”๋‰ด๋ฅผ ๊ณจ๋ผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n");
                System.out.println("[ " + category + " MENU ]");
                for (Product food : product)
                    if (food.getCategory().equals(category))
                        categoryProduct.add(food);
                for (Product food : categoryProduct) {
                    i++;
                    System.out.printf("%d. ", i);
                    food.show();
                }
                input = sc.nextInt();
            }while (0>input||input>i);
            if(categoryProduct.get(input - 1).getSizeupPrice()!=0){
                do{
                    clearScreen();
                    categoryProduct.get(input - 1).show();
                    System.out.println("์œ„ ๋ฉ”๋‰ด์˜ ์–ด๋–ค ์˜ต์…˜์œผ๋กœ ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
                    System.out.printf("1. Single(W" + categoryProduct.get(input - 1).getPrice() + ")        2. Double(W"+ categoryProduct.get(input - 1).getSizeupPrice()+")\n");
                    yesNo = sc.nextInt();
                }while(yesNo<1||yesNo>2);
                if(yesNo==2)
                    order.addorder(categoryProduct.get(input - 1),categoryProduct.get(input - 1).getSizeupPrice());
                else
                    order.addorder(categoryProduct.get(input - 1));
            }
            else
                order.addorder(categoryProduct.get(input - 1));
        }
        }


    public void orderMenu() throws InterruptedException {
        int yesNo;
        Scanner sc = new Scanner(System.in);
        clearScreen();
        System.out.println("์•„๋ž˜์™€ ๊ฐ™์ด ์ฃผ๋ฌธ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n");
        System.out.println("[ ORDERS ]");
        order.show();
        order.total();
        if (order.getTotalPrice() != 0) {
            do {
                clearScreen();
                System.out.println("์•„๋ž˜์™€ ๊ฐ™์ด ์ฃผ๋ฌธ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n");
                System.out.println("[ ORDERS ]");
                order.show();
                order.total();
                System.out.println("\n1. ์ฃผ๋ฌธ        2. ๋ฉ”๋‰ดํŒ\n");
                yesNo = sc.nextInt();
                if (yesNo == 1) {
                    clearScreen();
                    System.out.println("์ฃผ๋ฌธ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!\n");
                    System.out.printf("๋Œ€๊ธฐ๋ฒˆํ˜ธ๋Š” [ " + count++ + " ] ๋ฒˆ ์ž…๋‹ˆ๋‹ค.\n");
                    System.out.printf("(3์ดˆํ›„ ๋ฉ”๋‰ดํŒ์œผ๋กœ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค.)");
                    sell += order.getTotalPrice();
                    order.sold();
                    order.cancelorder();
                    Thread.sleep(3000);
                    clearScreen();
                } else if (yesNo == 2)
                    clearScreen();
            } while (yesNo < 1 || yesNo > 2);
        }
        else{
            System.out.println("์žฅ๋ฐ”๊ตฌ๋‹ˆ๊ฐ€ ๋น„์—ˆ์Šต๋‹ˆ๋‹ค.\n");
            System.out.printf("(3์ดˆํ›„ ๋ฉ”๋‰ดํŒ์œผ๋กœ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค.)");
            Thread.sleep(3000);
            clearScreen();
        }

    }

    public void cancelMenu(){
        int yesNo;
        Scanner sc = new Scanner(System.in);
        clearScreen();
        System.out.println("์ง„ํ–‰ํ•˜๋˜ ์ฃผ๋ฌธ์„ ์ทจ์†Œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
        System.out.println("1. ํ™•์ธ        2. ์ทจ์†Œ");
        yesNo = sc.nextInt();
        if (yesNo == 1) {
            order.cancelorder();
            clearScreen();
            System.out.println("์ง„ํ–‰ํ•˜๋˜ ์ฃผ๋ฌธ์ด ์ทจ์†Œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.\n");
        } else {
            clearScreen();
        }
    }

    public static void clearScreen() {
        for (int i = 0; i < 80; i++)
            System.out.println("");
    }
}

์‹คํ–‰ํ™”๋ฉด

  1. ๋ฉ”์ธ ๋ฉ”๋‰ด ํ™”๋ฉด
  2. ์นดํ…Œ๊ณ ๋ฆฌ ๋ฉ”๋‰ด ํ™”๋ฉด
  3. ๊ตฌ๋งค ํ™”๋ฉด

    3-1. ์ถ”๊ฐ€๊ธฐ๋Šฅ) ์‚ฌ์ด์ฆˆ์—… ์˜ต์…˜์ด ์žˆ๋Š” ๋ฉ”๋‰ด์˜ ์šฐ
  4. ์ฃผ๋ฌธ ํ™”๋ฉด
  5. ์ฃผ๋ฌธ ์™„๋ฃŒ ํ™”๋ฉด
  6. ์ฃผ๋ฌธ ์ทจ์†Œ ํ™”๋ฉด

  7. ์ถ”๊ฐ€๊ธฐ๋Šฅ) ์ˆจ๊ฒจ์ง„ ๊ธฐ๋Šฅ์œผ๋กœ ์ด ํŒ๋งค๊ธˆ์•ก/์ด ํŒ๋งค์ƒํ’ˆ ๋ชฉ๋ก ์ถœ๋ ฅ

์˜ค๋Š˜์˜ ํšŒ๊ณ 

๋งŒ๋งŒํ•˜๊ฒŒ ์ƒ๊ฐํ–ˆ๋˜ ์ž๋ฐ”์˜€์ง€๋งŒ, ๋ง‰์ƒ ํด๋ž˜์Šค๋ฅผ ๋‹ค๋ฃจ๊ธฐ ์‹œ์ž‘ํ•˜๋‹ˆ ์ž๋ฐ”๋ฅผ ๋ฐฐ์šฐ๊ณ  ์ง€๋‚œ ์„ธ์›”์ด ์žˆ์–ด์„œ ์ธ์ง€ ์ž๋ฐ”๋ฅผ ์ฒ˜์Œ ๋ฐฐ์šฐ๋Š” ๊ธฐ๋ถ„์ด์—ˆ๋‹ค.
๋•๋ถ„์— ์ž๋ฐ”๋ฅผ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ๋‹ค์‹œ ๋ฐฐ์šฐ๊ณ  ์ตํžˆ๋Š” ๊ฐ’์ง„ ๊ฒฝํ—˜์ด์—ˆ๋‹ค.
์•ž์œผ๋กœ ๊ณต๋ถ€ํ•  Spring๋„ ๊ฐ™์€ ๋งˆ์Œ๊ฐ€์ง์œผ๋กœ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ํƒ„ํƒ„ํžˆ ๋‹ค์ ธ์•ผ๊ฒ ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์ฝ”๋”ฉ์ปจ๋ฒค์…˜์ข€ ์ตํ˜€์•ผ๊ฒ ๋‹คใ…‹ใ…‹
๊ธฐ์–ต์ด ๊ฐ€๋ฌผ๊ฐ€๋ฌผํ•˜๋„ค

profile
๊ฐœ๋ฐœํ•˜๋Š” ๊ธฐ๋ก์ž

0๊ฐœ์˜ ๋Œ“๊ธ€