-
[COS PRO 1급 기출문제 - Java] 1-1 음식전문점 운영Algorithm/COS PRO 1급 기출문제 2020. 12. 20. 17:59
문제 유형
빈칸 채우기
문제
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061// 하단에 import 를 추가할 수 있습니다.import java.util.*;class Main {interface DeliveryStore{public void setOrderList(String[] orderList);public int getTotalPrice();}class Food{public String name;public int price;public Food(String name, int price){this.name = name;this.price = price;}}class PizzaStore _______________ {private ArrayList<Food> menuList;private ArrayList<String> orderList;public PizzaStore(){//init menuListmenuList = new ArrayList<Food>();String[] menuNames = {"Cheese", "Potato", "Shrimp", "Pineapple", "Meatball"};int[] menuPrices = {11100, 12600, 13300, 21000, 19500};for(int i = 0; i < menuNames.length; i++)menuList.add(new Food(menuNames[i], menuPrices[i]));//init orderListorderList = new ArrayList<String>();}public _______________{for(int i = 0; i < orderList.length; i++)this.orderList.add(orderList[i]);}public ________________{int totalPrice = 0;Iterator<String> iter = orderList.iterator();while (iter.hasNext()) {String order = iter.next();for(int i = 0; i < menuList.size(); i++)if(order.equals(menuList.get(i).name))totalPrice += menuList.get(i).price;}return totalPrice;}}public int solution(String[] orderList) {DeliveryStore deliveryStore = new PizzaStore();deliveryStore.setOrderList(orderList);int totalPrice = deliveryStore.getTotalPrice();return totalPrice;}cs 풀이
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061// 하단에 import 를 추가할 수 있습니다.import java.util.*;class Main {interface DeliveryStore{public void setOrderList(String[] orderList);public int getTotalPrice();}class Food{public String name;public int price;public Food(String name, int price){this.name = name;this.price = price;}}class PizzaStore implements DeliveryStore {private ArrayList<Food> menuList;private ArrayList<String> orderList;public PizzaStore(){//init menuListmenuList = new ArrayList<Food>();String[] menuNames = {"Cheese", "Potato", "Shrimp", "Pineapple", "Meatball"};int[] menuPrices = {11100, 12600, 13300, 21000, 19500};for(int i = 0; i < menuNames.length; i++)menuList.add(new Food(menuNames[i], menuPrices[i]));//init orderListorderList = new ArrayList<String>();}public void setOrderList(String[] orderList){for(int i = 0; i < orderList.length; i++)this.orderList.add(orderList[i]);}public int getTotalPrice(){int totalPrice = 0;Iterator<String> iter = orderList.iterator();while (iter.hasNext()) {String order = iter.next();for(int i = 0; i < menuList.size(); i++)if(order.equals(menuList.get(i).name))totalPrice += menuList.get(i).price;}return totalPrice;}}public int solution(String[] orderList) {DeliveryStore deliveryStore = new PizzaStore();deliveryStore.setOrderList(orderList);int totalPrice = deliveryStore.getTotalPrice();return totalPrice;}cs 'Algorithm > COS PRO 1급 기출문제' 카테고리의 다른 글
[COS PRO 1급 기출문제 - Java] 1-5 소용돌이 수 (0) 2020.12.20 [COS PRO 1급 기출문제] 1-4 타임머신 (0) 2020.12.20 [COS PRO 1급 기출문제 - Java] 1-3 계산기 by 문자열 (0) 2020.12.20 [COS PRO 1급 기출문제 - Java] 1-2 해밍 거리 구하기 (0) 2020.12.20 [COS PRO 1급 기출문제 - Java]Intro (0) 2020.12.20