From 0aafec327c12333c0ede639b85b6863e6c94b65a Mon Sep 17 00:00:00 2001 From: jae57 Date: Sat, 9 Mar 2019 23:03:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[AutoVending]=20ADD=20|=20=EC=9E=90?= =?UTF-8?q?=ED=8C=90=EA=B8=B0=20=EA=B8=B0=EB=B3=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoVending/src/main/java/AdminMenu.java | 101 ++++++++++++++++++ KIMJIHYE/AutoVending/src/main/java/Item.java | 22 ++++ .../AutoVending/src/main/java/Machine.java | 92 ++++++++++++++++ KIMJIHYE/AutoVending/src/main/java/Main.java | 37 +++++++ KIMJIHYE/AutoVending/src/main/java/Menu.java | 9 ++ .../AutoVending/src/main/java/Report.java | 31 ++++++ .../AutoVending/src/main/java/UserMenu.java | 88 +++++++++++++++ 7 files changed, 380 insertions(+) create mode 100644 KIMJIHYE/AutoVending/src/main/java/AdminMenu.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/Item.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/Machine.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/Main.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/Menu.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/Report.java create mode 100644 KIMJIHYE/AutoVending/src/main/java/UserMenu.java diff --git a/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java b/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java new file mode 100644 index 0000000..abee5f0 --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java @@ -0,0 +1,101 @@ +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +public class AdminMenu implements Menu { + Scanner scanner = new Scanner(System.in); + private Machine machine; + private List items; + private Map stocks; + private Report report; + + public AdminMenu(Machine machine){ + this.machine = machine; + items = machine.getItems(); + stocks = machine.getStocks(); + report = machine.getReport(); + } + + public void showItems(){ + System.out.println("번호 상품명 제조사 용량 가격 재고"); + for(Item item: items){ + System.out.print(item); + System.out.println(stocks.get(item)+"개"); + } + } + + public void showMenus(){ + System.out.println("========= 관리자 메뉴 ======="); + System.out.println("1. 재고 채우기"); + System.out.println("2. 사용자의 구매 이력 보기"); + System.out.print("메뉴 번호를 입력하세요 :) "); + } + + public void doProcess(int menuNum){ + switch(menuNum){ + case 1: + showItems(); + fillItems(); + break; + case 2: + report.print(); + break; + default: + System.out.println("잘못된 입력.."); + break; + + } + } + + public void raisePrice(int itemId, int amount){ + Item item = machine.getItem(itemId); + item.price += amount; + } + + public void reducePrice(int itemId, int amount){ + Item item = machine.getItem(itemId); + item.price -= amount; + } + + public void fillItems(){ + int capacity = machine.getCapacity(); + Map needToBuy = new HashMap<>(); + + for( Item item : stocks.keySet()){ + if(stocks.get(item) < capacity){ + int amount = capacity - stocks.get(item); + //report.itemIn(item,amount); + needToBuy.put(item,amount); + } + } + + String list=""; + for(Item item: needToBuy.keySet()){ + list+= item.name+" "+needToBuy.get(item)+"개, "; + } + list = list.substring(0,list.length()-2); + + System.out.println("재고를 꽉 채우려면"); + System.out.println(list+"가 필요합니다."); + System.out.print("주문하시겠습니까? (Y/N) "); + switch(scanner.next()){ + case "Y": + case "y": + for(Item item : needToBuy.keySet()){ + machine.fill(item,needToBuy.get(item)); + } + break; + case "N": + case "n": + System.out.println("관리자 메뉴를 종료합니다. :)"); + System.out.println("============================="); + break; + } + } + + + + + +} diff --git a/KIMJIHYE/AutoVending/src/main/java/Item.java b/KIMJIHYE/AutoVending/src/main/java/Item.java new file mode 100644 index 0000000..f44befd --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/Item.java @@ -0,0 +1,22 @@ +public class Item { + int itemId; + String brand; + int weight; + int price; + String name; + long date; + + public Item(int itemId,String brand, int weight, int price, String name){ + this.itemId = itemId; + this.brand = brand; + this.weight = weight; + this.price = price; + this.name= name; + this.date = System.currentTimeMillis(); + } + + @Override + public String toString() { + return itemId+". "+name+" "+brand+" "+weight+"ml "+price+"원 "; + } +} diff --git a/KIMJIHYE/AutoVending/src/main/java/Machine.java b/KIMJIHYE/AutoVending/src/main/java/Machine.java new file mode 100644 index 0000000..8219efc --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/Machine.java @@ -0,0 +1,92 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Machine { + private Report report; + private List items; + private Map stocks; + private int capacity = 10; + private int money; + + public Machine(){ + items = new ArrayList<>(); + items.add(new Item(1,"해태",240,1000,"코코팜")); + items.add(new Item(2,"동아오츠카",240,900,"데자와")); + items.add(new Item(3,"롯데",150,500,"레쓰비")); + items.add(new Item(4,"롯데",210,900,"칠성사이다")); + items.add(new Item(5,"델몬트",240,1100,"오렌지에이드")); + + report = new Report(); + + stocks = new HashMap(); + for( Item item : items){ + stocks.put(item,capacity); + } + } + + public void setMoney(int money){ + this.money = money; + } + + public int getMoney(){ + return money; + } + + public int getCapacity(){ + return capacity; + } + + public void setCapacity(int capacity){ + this.capacity = capacity; + } + + public Item getItem(int itemId){ + Item it = null; + for(Item item: items){ + if(item.itemId == itemId) { + it = item; + } + } + + if (it == null) { + System.out.println("찾으시는 상품이 없습니다."); + return null; + }else{ + return it; + } + } + + public void fill(Item item, int amount){ + int remains= stocks.get(item); + stocks.put(item,remains+amount); + } + + public void buy(int itemId){ + for( Item item: items){ + if(item.itemId == itemId){ + Item it = item; + int remains = stocks.get(it); + if(remains==0){ + System.out.println("Sold Out!!"); + }else{ + stocks.put(it,remains-1); + money-= it.price; + } + } + } + } + + public List getItems(){ + return items; + } + + public Map getStocks(){ + return stocks; + } + + public Report getReport(){ + return report; + } +} diff --git a/KIMJIHYE/AutoVending/src/main/java/Main.java b/KIMJIHYE/AutoVending/src/main/java/Main.java new file mode 100644 index 0000000..ae34a89 --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/Main.java @@ -0,0 +1,37 @@ +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Machine machine = new Machine(); + Menu menu = null; + + System.out.println(" 자팡기자판기 "); + while(true){ + System.out.println("1. 상품 구매(사용자 메뉴)\n2. 상품 관리(관리자 메뉴)"); + System.out.print("메뉴 번호를 입력하세요 :) "); + switch(scanner.nextInt()){ + case 1: + menu = new UserMenu(machine); + menu.showItems(); + menu.doProcess(); + break; + case 2: + menu = new AdminMenu(machine); + menu.showItems(); + menu.showMenus(); + menu.doProcess(scanner.nextInt()); + break; + } + + + + + } + + + + } + +} diff --git a/KIMJIHYE/AutoVending/src/main/java/Menu.java b/KIMJIHYE/AutoVending/src/main/java/Menu.java new file mode 100644 index 0000000..04154b2 --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/Menu.java @@ -0,0 +1,9 @@ +public interface Menu { + void showItems(); + default void doProcess(){}; + default void doProcess(int menuNum){}; + default void showMenus(){}; + default boolean showCanBuy(int money){ + return true; + }; +} diff --git a/KIMJIHYE/AutoVending/src/main/java/Report.java b/KIMJIHYE/AutoVending/src/main/java/Report.java new file mode 100644 index 0000000..60d5c56 --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/Report.java @@ -0,0 +1,31 @@ +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +public class Report { + List reports; + + public Report(){ + this.reports = new ArrayList(); + } + + /*public void itemIn(Item item, int amount){ + reports.add("구입 | "+item.name+" "+amount+"개"); + }*/ + + public void write(String item){ + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String log = (reports.size()+1)+". "+item+" 1개 "+df.format(System.currentTimeMillis()); + reports.add(log); + } + + public void print(){ + System.out.println("====== 사용자의 구매 이력 ======="); + for(String report : reports){ + System.out.println(report); + } + System.out.println("================================="); + } + +} diff --git a/KIMJIHYE/AutoVending/src/main/java/UserMenu.java b/KIMJIHYE/AutoVending/src/main/java/UserMenu.java new file mode 100644 index 0000000..b850a94 --- /dev/null +++ b/KIMJIHYE/AutoVending/src/main/java/UserMenu.java @@ -0,0 +1,88 @@ +import java.util.List; +import java.util.Scanner; + +public class UserMenu implements Menu { + Scanner scanner = new Scanner(System.in); + private Machine machine; + private Report report; + List items; + int minPrice; + + public UserMenu(Machine machine){ + this.machine = machine; + items = machine.getItems(); + report = machine.getReport(); + + minPrice = items.get(0).price; + for(Item item: items){ + if(item.price < minPrice){ + minPrice = item.price; + } + } + + System.out.println("=========== 상품 구매 =========="); + } + + public void doProcess(){ + boolean isEnd = false; + while(true){ + System.out.print("돈을 넣으세요 :) "); + int money = scanner.nextInt(); + machine.setMoney(machine.getMoney()+money); + if(showCanBuy(machine.getMoney())){ + System.out.print("원하는 상품을 선택하세요 :) "); + int itemId = scanner.nextInt(); + String item = machine.getItem(itemId).name; + machine.buy(itemId); + System.out.println(item+"을 구입했습니다."); + report.write(item); + System.out.println("더 구매하시겠습니까? (Y/N) "); + switch(scanner.next()){ + case "Y": + case "y": + break; + case "N": + case "n": + System.out.println("거스름돈 "+machine.getMoney()+"원을 가져가세요 :) "); + machine.setMoney(0); + isEnd=true; + break; + default: + System.out.println("잘못된 입력.. 처음으로 이동합니다."); + } + }else{ + continue; + } + System.out.println("======================================="); + if(isEnd){ + break; + } + } + + } + + public void showItems(){ + System.out.println("번호 상품명 제조사 용량 가격"); + for(Item item: items){ + System.out.println(item); + } + } + + public boolean showCanBuy(int money){ + if(money "); + + for(Item item: items){ + if(item.price <= money){ + System.out.println(item.itemId+". "+item.name+" "+item.price+"원"); + } + } + return true; + } + } + +} From cff07c239940aceb930e5a8ff29a7c8726b6ce19 Mon Sep 17 00:00:00 2001 From: jae57 Date: Sat, 9 Mar 2019 23:14:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[AutoVending]=20Fix=20|=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoVending/src/main/java/AdminMenu.java | 51 +++++++-------- KIMJIHYE/AutoVending/src/main/java/Item.java | 6 +- .../AutoVending/src/main/java/Machine.java | 64 +++++++++---------- KIMJIHYE/AutoVending/src/main/java/Main.java | 7 +- KIMJIHYE/AutoVending/src/main/java/Menu.java | 13 ++-- .../AutoVending/src/main/java/Report.java | 14 ++-- .../AutoVending/src/main/java/UserMenu.java | 44 ++++++------- 7 files changed, 95 insertions(+), 104 deletions(-) diff --git a/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java b/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java index abee5f0..f22ea54 100644 --- a/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java +++ b/KIMJIHYE/AutoVending/src/main/java/AdminMenu.java @@ -7,33 +7,33 @@ public class AdminMenu implements Menu { Scanner scanner = new Scanner(System.in); private Machine machine; private List items; - private Map stocks; + private Map stocks; private Report report; - public AdminMenu(Machine machine){ + public AdminMenu(Machine machine) { this.machine = machine; items = machine.getItems(); stocks = machine.getStocks(); report = machine.getReport(); } - public void showItems(){ + public void showItems() { System.out.println("번호 상품명 제조사 용량 가격 재고"); - for(Item item: items){ + for (Item item : items) { System.out.print(item); - System.out.println(stocks.get(item)+"개"); + System.out.println(stocks.get(item) + "개"); } } - public void showMenus(){ + public void showMenus() { System.out.println("========= 관리자 메뉴 ======="); System.out.println("1. 재고 채우기"); System.out.println("2. 사용자의 구매 이력 보기"); System.out.print("메뉴 번호를 입력하세요 :) "); } - public void doProcess(int menuNum){ - switch(menuNum){ + public void doProcess(int menuNum) { + switch (menuNum) { case 1: showItems(); fillItems(); @@ -48,42 +48,42 @@ public void doProcess(int menuNum){ } } - public void raisePrice(int itemId, int amount){ + public void raisePrice(int itemId, int amount) { Item item = machine.getItem(itemId); item.price += amount; } - public void reducePrice(int itemId, int amount){ + public void reducePrice(int itemId, int amount) { Item item = machine.getItem(itemId); item.price -= amount; } - public void fillItems(){ + public void fillItems() { int capacity = machine.getCapacity(); - Map needToBuy = new HashMap<>(); + Map needToBuy = new HashMap<>(); - for( Item item : stocks.keySet()){ - if(stocks.get(item) < capacity){ + for (Item item : stocks.keySet()) { + if (stocks.get(item) < capacity) { int amount = capacity - stocks.get(item); //report.itemIn(item,amount); - needToBuy.put(item,amount); + needToBuy.put(item, amount); } } - String list=""; - for(Item item: needToBuy.keySet()){ - list+= item.name+" "+needToBuy.get(item)+"개, "; + String list = ""; + for (Item item : needToBuy.keySet()) { + list += item.name + " " + needToBuy.get(item) + "개, "; } - list = list.substring(0,list.length()-2); + list = list.substring(0, list.length() - 2); System.out.println("재고를 꽉 채우려면"); - System.out.println(list+"가 필요합니다."); + System.out.println(list + "가 필요합니다."); System.out.print("주문하시겠습니까? (Y/N) "); - switch(scanner.next()){ + switch (scanner.next()) { case "Y": case "y": - for(Item item : needToBuy.keySet()){ - machine.fill(item,needToBuy.get(item)); + for (Item item : needToBuy.keySet()) { + machine.fill(item, needToBuy.get(item)); } break; case "N": @@ -93,9 +93,4 @@ public void fillItems(){ break; } } - - - - - } diff --git a/KIMJIHYE/AutoVending/src/main/java/Item.java b/KIMJIHYE/AutoVending/src/main/java/Item.java index f44befd..b88ed0e 100644 --- a/KIMJIHYE/AutoVending/src/main/java/Item.java +++ b/KIMJIHYE/AutoVending/src/main/java/Item.java @@ -6,17 +6,17 @@ public class Item { String name; long date; - public Item(int itemId,String brand, int weight, int price, String name){ + public Item(int itemId, String brand, int weight, int price, String name) { this.itemId = itemId; this.brand = brand; this.weight = weight; this.price = price; - this.name= name; + this.name = name; this.date = System.currentTimeMillis(); } @Override public String toString() { - return itemId+". "+name+" "+brand+" "+weight+"ml "+price+"원 "; + return itemId + ". " + name + " " + brand + " " + weight + "ml " + price + "원 "; } } diff --git a/KIMJIHYE/AutoVending/src/main/java/Machine.java b/KIMJIHYE/AutoVending/src/main/java/Machine.java index 8219efc..3461a05 100644 --- a/KIMJIHYE/AutoVending/src/main/java/Machine.java +++ b/KIMJIHYE/AutoVending/src/main/java/Machine.java @@ -6,46 +6,46 @@ public class Machine { private Report report; private List items; - private Map stocks; + private Map stocks; private int capacity = 10; private int money; - public Machine(){ + public Machine() { items = new ArrayList<>(); - items.add(new Item(1,"해태",240,1000,"코코팜")); - items.add(new Item(2,"동아오츠카",240,900,"데자와")); - items.add(new Item(3,"롯데",150,500,"레쓰비")); - items.add(new Item(4,"롯데",210,900,"칠성사이다")); - items.add(new Item(5,"델몬트",240,1100,"오렌지에이드")); + items.add(new Item(1, "해태", 240, 1000, "코코팜")); + items.add(new Item(2, "동아오츠카", 240, 900, "데자와")); + items.add(new Item(3, "롯데", 150, 500, "레쓰비")); + items.add(new Item(4, "롯데", 210, 900, "칠성사이다")); + items.add(new Item(5, "델몬트", 240, 1100, "오렌지에이드")); report = new Report(); - stocks = new HashMap(); - for( Item item : items){ - stocks.put(item,capacity); + stocks = new HashMap(); + for (Item item : items) { + stocks.put(item, capacity); } } - public void setMoney(int money){ + public void setMoney(int money) { this.money = money; } - public int getMoney(){ + public int getMoney() { return money; } - public int getCapacity(){ + public int getCapacity() { return capacity; } - public void setCapacity(int capacity){ + public void setCapacity(int capacity) { this.capacity = capacity; } - public Item getItem(int itemId){ + public Item getItem(int itemId) { Item it = null; - for(Item item: items){ - if(item.itemId == itemId) { + for (Item item : items) { + if (item.itemId == itemId) { it = item; } } @@ -53,40 +53,40 @@ public Item getItem(int itemId){ if (it == null) { System.out.println("찾으시는 상품이 없습니다."); return null; - }else{ + } else { return it; } } - public void fill(Item item, int amount){ - int remains= stocks.get(item); - stocks.put(item,remains+amount); + public void fill(Item item, int amount) { + int remains = stocks.get(item); + stocks.put(item, remains + amount); } - public void buy(int itemId){ - for( Item item: items){ - if(item.itemId == itemId){ + public void buy(int itemId) { + for (Item item : items) { + if (item.itemId == itemId) { Item it = item; int remains = stocks.get(it); - if(remains==0){ + if (remains == 0) { System.out.println("Sold Out!!"); - }else{ - stocks.put(it,remains-1); - money-= it.price; + } else { + stocks.put(it, remains - 1); + money -= it.price; } } } } - public List getItems(){ + public List getItems() { return items; } - - public Map getStocks(){ + + public Map getStocks() { return stocks; } - public Report getReport(){ + public Report getReport() { return report; } } diff --git a/KIMJIHYE/AutoVending/src/main/java/Main.java b/KIMJIHYE/AutoVending/src/main/java/Main.java index ae34a89..f749eac 100644 --- a/KIMJIHYE/AutoVending/src/main/java/Main.java +++ b/KIMJIHYE/AutoVending/src/main/java/Main.java @@ -8,10 +8,10 @@ public static void main(String[] args) { Menu menu = null; System.out.println(" 자팡기자판기 "); - while(true){ + while (true) { System.out.println("1. 상품 구매(사용자 메뉴)\n2. 상품 관리(관리자 메뉴)"); System.out.print("메뉴 번호를 입력하세요 :) "); - switch(scanner.nextInt()){ + switch (scanner.nextInt()) { case 1: menu = new UserMenu(machine); menu.showItems(); @@ -26,12 +26,9 @@ public static void main(String[] args) { } - - } - } } diff --git a/KIMJIHYE/AutoVending/src/main/java/Menu.java b/KIMJIHYE/AutoVending/src/main/java/Menu.java index 04154b2..b80c7d0 100644 --- a/KIMJIHYE/AutoVending/src/main/java/Menu.java +++ b/KIMJIHYE/AutoVending/src/main/java/Menu.java @@ -1,9 +1,12 @@ public interface Menu { void showItems(); - default void doProcess(){}; - default void doProcess(int menuNum){}; - default void showMenus(){}; - default boolean showCanBuy(int money){ + default void doProcess() { + } + default void doProcess(int menuNum) { + } + default void showMenus() { + } + default boolean showCanBuy(int money) { return true; - }; + } } diff --git a/KIMJIHYE/AutoVending/src/main/java/Report.java b/KIMJIHYE/AutoVending/src/main/java/Report.java index 60d5c56..b9807b0 100644 --- a/KIMJIHYE/AutoVending/src/main/java/Report.java +++ b/KIMJIHYE/AutoVending/src/main/java/Report.java @@ -6,23 +6,19 @@ public class Report { List reports; - public Report(){ + public Report() { this.reports = new ArrayList(); } - /*public void itemIn(Item item, int amount){ - reports.add("구입 | "+item.name+" "+amount+"개"); - }*/ - - public void write(String item){ + public void write(String item) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String log = (reports.size()+1)+". "+item+" 1개 "+df.format(System.currentTimeMillis()); + String log = (reports.size() + 1) + ". " + item + " 1개 " + df.format(System.currentTimeMillis()); reports.add(log); } - public void print(){ + public void print() { System.out.println("====== 사용자의 구매 이력 ======="); - for(String report : reports){ + for (String report : reports) { System.out.println(report); } System.out.println("================================="); diff --git a/KIMJIHYE/AutoVending/src/main/java/UserMenu.java b/KIMJIHYE/AutoVending/src/main/java/UserMenu.java index b850a94..0da935e 100644 --- a/KIMJIHYE/AutoVending/src/main/java/UserMenu.java +++ b/KIMJIHYE/AutoVending/src/main/java/UserMenu.java @@ -8,14 +8,14 @@ public class UserMenu implements Menu { List items; int minPrice; - public UserMenu(Machine machine){ + public UserMenu(Machine machine) { this.machine = machine; items = machine.getItems(); report = machine.getReport(); minPrice = items.get(0).price; - for(Item item: items){ - if(item.price < minPrice){ + for (Item item : items) { + if (item.price < minPrice) { minPrice = item.price; } } @@ -23,62 +23,62 @@ public UserMenu(Machine machine){ System.out.println("=========== 상품 구매 =========="); } - public void doProcess(){ + public void doProcess() { boolean isEnd = false; - while(true){ + while (true) { System.out.print("돈을 넣으세요 :) "); int money = scanner.nextInt(); - machine.setMoney(machine.getMoney()+money); - if(showCanBuy(machine.getMoney())){ + machine.setMoney(machine.getMoney() + money); + if (showCanBuy(machine.getMoney())) { System.out.print("원하는 상품을 선택하세요 :) "); int itemId = scanner.nextInt(); String item = machine.getItem(itemId).name; machine.buy(itemId); - System.out.println(item+"을 구입했습니다."); + System.out.println(item + "을 구입했습니다."); report.write(item); System.out.println("더 구매하시겠습니까? (Y/N) "); - switch(scanner.next()){ + switch (scanner.next()) { case "Y": case "y": break; case "N": case "n": - System.out.println("거스름돈 "+machine.getMoney()+"원을 가져가세요 :) "); + System.out.println("거스름돈 " + machine.getMoney() + "원을 가져가세요 :) "); machine.setMoney(0); - isEnd=true; + isEnd = true; break; default: System.out.println("잘못된 입력.. 처음으로 이동합니다."); } - }else{ + } else { continue; } System.out.println("======================================="); - if(isEnd){ + if (isEnd) { break; } } } - public void showItems(){ + public void showItems() { System.out.println("번호 상품명 제조사 용량 가격"); - for(Item item: items){ + for (Item item : items) { System.out.println(item); } } - public boolean showCanBuy(int money){ - if(money "); - for(Item item: items){ - if(item.price <= money){ - System.out.println(item.itemId+". "+item.name+" "+item.price+"원"); + for (Item item : items) { + if (item.price <= money) { + System.out.println(item.itemId + ". " + item.name + " " + item.price + "원"); } } return true;