Algorithm/COS PRO 1급 기출문제
[COS PRO 1급 기출문제 - Java] 1-1 음식전문점 운영
goakgoak
2020. 12. 20. 17:59
문제 유형
빈칸 채우기
문제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// 하단에 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 menuList
menuList = 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 orderList
orderList = 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 |
풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// 하단에 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 menuList
menuList = 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 orderList
orderList = 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 |