-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffee.java
More file actions
81 lines (65 loc) · 2.62 KB
/
Copy pathCoffee.java
File metadata and controls
81 lines (65 loc) · 2.62 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package ezen_coffee_hsw;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Coffee {
// 싱글톤 생성
private static Coffee instance;
private Coffee() {
};
public static Coffee getInstance() {
if (instance == null) {
instance = new Coffee();
}
return instance;
}
// 메뉴 리스트로 저장
ArrayList<String> coffeList; // 메뉴 리스트
ArrayList<Integer> coffePrice; // 각 메뉴 가격
Map<String, Integer> menu;
// 커피 메뉴 보여주기
public void getMenu() {
menu = new LinkedHashMap<String, Integer>();
coffeList = new ArrayList<>();
coffePrice = new ArrayList<>();
// 메뉴 입력
coffeList.add("아메리카노");
coffeList.add("카푸치노");
coffeList.add("아이스 아메리카노");
coffeList.add("카라멜 마끼아또");
coffeList.add("카페라떼");
coffeList.add("카페모카");
// 가격 입력
coffePrice.add(2000); // 아메리카노
coffePrice.add(4500); // 카푸치노
coffePrice.add(2500); // 아이스 아메리카노
coffePrice.add(4000); // 카라멜 마끼아또
coffePrice.add(3000); // 카페라떼
coffePrice.add(3500); // 카페모카
// 맵에 저장 - 키 : 메뉴이름 벨류 : 가격
for (int i = 0; i < coffeList.size(); i++) {
menu.put(coffeList.get(i), coffePrice.get(i));
}
DecimalFormat f = new DecimalFormat("0,000원");
// 반복문으로 전체 메뉴 보여주기
StringBuffer st = new StringBuffer();
st.append("\n\n ")
.append("+----------------------------------------------------+\n ")
.append("|===================== 메뉴판 =======================| \n ")
.append("| Menu Price | \n");
System.out.print(st.toString());
int s = 1;
for (Entry<String, Integer> get : menu.entrySet()) {
System.out.printf(" | [%d번] %-11s\t: %s |\n", s, get.getKey(), f.format(get.getValue()));
s++;
}
System.out.println(" +----------------------------------------------------+\n");
}// getMenu 끝
// 메뉴 확인용 메인메소드
// public static void main(String[] args) {
// Coffee coffee = Coffee.getInstance();
// coffee.getMenu();
// }
}