๐ข ๋ด๊ฐ ์ข์ํ๋ ์นดํ ๋๋ ํจ์คํธํธ๋์ ์ ํค์ค์คํฌ๋ฅผ ๋ง๋ค์ด๋ณด์!
- ์ง๊ธ๊น์ง ๋ฐฐ์์จ Java ์ธ์ด๋ฅผ ์ฌ์ฉํ์ฌ ํค์ค์คํฌ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด๋ด ์๋ค.
- ๋ด๊ฐ ์ข์ํ๋ ์นดํ๋ ํจ์คํธํธ๋์ ์ ๋ฉ๋ดํ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ ์ฌ๋ฐ๊ฒ ์ฃ ?
- ๋ฉ์ธ ๋ฉ๋ดํ ํ๋ฉด
- ๋ฉ์ธ ๋ฉ๋ดํ์ด ์ถ๋ ฅ๋๋ฉฐ ๋ฉ๋ดํ์๋ ์ํ ๋ฉ๋ด๊ฐ ์ถ๋ ฅ ๋ฉ๋๋ค.
- ์ํ ๋ฉ๋ด๋ ๊ฐ๋จํ ์ค๋ช ๊ณผ ํจ๊ป ์ถ๋ ฅ ๋๋ฉฐ ์ต์ 3๊ฐ ์ด์ ์ถ๋ ฅ ๋ฉ๋๋ค.
- ์ํ ๋ฉ๋ด ์๋์๋ Order(์ฃผ๋ฌธ)์ Cancel(์ฃผ๋ฌธ ์ทจ์) ์ต์ ์ ์ถ๋ ฅํด์ค๋๋ค.
- ์ํ ๋ฉ๋ดํ ํ๋ฉด
- ์ํ ๋ฉ๋ด ์ ํ ์ ํด๋น ์นดํ ๊ณ ๋ฆฌ์ ๋ฉ๋ดํ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
- ๋ฉ๋ดํ์๋ ๊ฐ ๋ฉ๋ด์ ์ด๋ฆ๊ณผ ๊ฐ๊ฒฉ๊ณผ ๊ฐ๋จํ ์ค๋ช ์ด ํ์๋ฉ๋๋ค.
- ๊ตฌ๋งค ํ๋ฉด
- ์ํ ์ ํ ์ ํด๋น ์ํ์ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ ์ง ํ์ธํ๋ ๋ฌธ๊ตฌ๊ฐ ์ถ๋ ฅ ๋ฉ๋๋ค.
1.ํ์ธ
์ ๋ ฅ ์ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์๋ค๋ ์๋ด ๋ฌธ๊ตฌ์ ํจ๊ป ๋ฉ์ธ ๋ฉ๋ด๋ก ๋ค์ ์ถ๋ ฅ ๋ฉ๋๋ค.- ์ฃผ๋ฌธ ํ๋ฉด
5.Order
์ ๋ ฅ ์ ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก์ ์ถ๋ ฅํด์ค๋๋ค.- ์ฅ๋ฐ๊ตฌ๋์์๋ ์ถ๊ฐ๋ ๋ฉ๋ด๋ค๊ณผ ์ด ๊ฐ๊ฒฉ์ ํฉ์ ์ถ๋ ฅํด์ค๋๋ค.
1.์ฃผ๋ฌธ
์ ๋ ฅ ์ ์ฃผ๋ฌธ์๋ฃ ํ๋ฉด์ผ๋ก ๋์ด๊ฐ๊ณ ,2.๋ฉ๋ดํ
์ ๋ ฅ ์ ๋ค์ ๋ฉ์ธ ๋ฉ๋ด๋ก ๋์์ต๋๋ค.- ์ฃผ๋ฌธ์๋ฃ ํ๋ฉด
1.์ฃผ๋ฌธ
์ ๋ ฅ ์ ๋๊ธฐ๋ฒํธ๋ฅผ ๋ฐ๊ธํด์ค๋๋ค.- ์ฅ๋ฐ๊ตฌ๋๋ ์ด๊ธฐํ๋๊ณ 3์ด ํ์ ๋ฉ์ธ ๋ฉ๋ดํ์ผ๋ก ๋์๊ฐ๋๋ค.
- ์ฃผ๋ฌธ ์ทจ์ ํ๋ฉด
- ๋ฉ๋ดํ์์
6.Cancel
์ ๋ ฅ์ ์ฃผ๋ฌธ์ ์ทจ์ํ ์ง ํ์ธ์ ์์ฒญํ๋ ๋ฌธ๊ตฌ๊ฐ ์ถ๋ ฅ ๋ฉ๋๋ค.1.ํ์ธ
์ ์ ๋ ฅํ๋ฉด ์ฅ๋ฐ๊ตฌ๋๋ ์ด๊ธฐํ๋๊ณ ์ทจ์ ์๋ฃ ๋ฌธ๊ตฌ์ ํจ๊ป ๋ฉ๋ดํ์ด ์ถ๋ ฅ ๋ฉ๋๋ค.
- ์ฃผ๋ฌธ ๊ฐ์ ๊ธฐ๋ฅ ์ถ๊ฐ
- ์ฅ๋ฐ๊ตฌ๋์ ๋๊ฐ์ ์ํ์ด ๋ด๊ธฐ๋ฉด ์ฃผ๋ฌธ ํ๋ฉด์์ ์ํ ๊ฐ์๊ฐ ์ถ๋ ฅ ๋๋๋ก ํฉ๋๋ค.
- ์ํ ์ต์ ๊ธฐ๋ฅ ์ถ๊ฐ
- ์ํ์ ์ต์ ์ ์ ํ ํ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ ํ ์ ์๊ฒ ์ธ๋ถํ ํฉ๋๋ค.
- ์ด ํ๋งค๊ธ์ก ์กฐํ ๊ธฐ๋ฅ ์ถ๊ฐ
- ๊ตฌ๋งค๊ฐ ์๋ฃ๋ ๋๋ง๋ค ์ด ํ๋งค ๊ธ์ก์ ๋์ ํด์ค๋๋ค.
- ์จ๊ฒจ์ง ๊ธฐ๋ฅ์ผ๋ก 0๋ฒ ์ ๋ ฅ ์ ์ด ํ๋งค๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค.
- ์ด ํ๋งค์ํ ๋ชฉ๋ก ์กฐํ ๊ธฐ๋ฅ ์ถ๊ฐ
- ๊ตฌ๋งค๊ฐ ์๋ฃ๋ ๋๋ง๋ค ํ๋งค ์ํ ๋ชฉ๋ก์ ์ ์ฅํด์ค๋๋ค.
- ์จ๊ฒจ์ง ๊ธฐ๋ฅ์ผ๋ก 0๋ฒ ์ ๋ ฅ ์ ์ด ํ๋งค ์ํ ๋ชฉ๋ก์ ์ถ๋ ฅํฉ๋๋ค.
Main : KioskService ํด๋์ค๋ฅผ ์คํ์ํค๋ ๋ฉ์ธํด๋์ค
KioskService : ๋ฉ๋ดํ ๋ชฉ๋ก์ ๋ก๋(initMenu)ํ๊ณ , ํ๋ฉด์ถ๋ ฅ๊ณผ ์ฌ์ฉ์ ์ ๋ ฅ์ ๋ฐ์ ์ํฉ์ ๋ง๋ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ์กํฐ๋ธ ํด๋์ค
Menu : ๋ฒ๊ฑฐ๋ฅ, ์๋ฃ๋ฅ ๋ฑ ์นดํ ๊ณ ๋ฆฌ๋ฉ๋ด๋ฅผ ๋ํ๋ด๊ธฐ ์ํ ๋ฉ๋ด ํด๋์ค
Product : Menu ํด๋์ค๋ฅผ ์์๋ฐ๋ ์์ ํด๋์ค. @@๋ฒ๊ฑฐ, @@์๋ฃ ๋ฑ ์นดํ ๊ณ ๋ฆฌ ๋ด ๋ค์ด๊ฐ ์ํ์ ์ค๊ณ๋
Order : ์ฃผ๋ฌธ ์ฒ๋ฆฌ, ์ฃผ๋ฌธ ์ทจ์, ์ด ํ๋งค๋ชฉ๋ก, ์ด ํ๋งค๊ธ์ก ๋ฑ ์ฃผ๋ฌธ๊ณผ ๊ด๋ จ๋ ์ญํ ์ ์ํํ๋ ํด๋์ค
- kiosk๋ฅผ ์ ์ธํ๊ณ , ๋ฉ๋ดํ ๋ชฉ๋ก์ ๋ก๋ ๋ฐ ํ๋ฉด์ถ๋ ฅ ๋ฉ์๋๋ฅผ ํธ์ถ
public class Main {
public static void main(String[] args) throws InterruptedException {
KioskService kiosk = new KioskService();
kiosk.initMenu();
kiosk.mainMenu();
}
}
- ์ด๋ฆ๊ณผ ์ค๋ช ํ๋๋ฅผ ๊ฐ์ง๋ ํด๋์ค๋ก ์์ฑ
- ๋ณ์๋ฅผ 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);
}
}
- ์ด๋ฆ, ๊ฐ๊ฒฉ, ์ค๋ช ํ๋๋ฅผ ๊ฐ์ง๋ ํด๋์ค
- ์นดํ ๊ณ ๋ฆฌ ์๋ณ์ ์ํ ์นดํ ๊ณ ๋ฆฌ ํ๋, ์ฌ์ด์ฆ์ ์ต์ ์ถ๊ฐ๋ฅผ ์ํ ์ฌ์ด์ฆ์ ๊ฐ๊ฒฉ ํ๋ ์ถ๊ฐ
- ๋ถ๋ชจ ๋ฉ์๋ 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());
}
}
- ์ฃผ๋ฌธ๊ด๋ จ ์ญํ ์ ์ํํ๋ ํด๋์ค
- ๋ณ์๋ฅผ 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;}
}
- 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("");
}
}
- ๋ฉ์ธ ๋ฉ๋ด ํ๋ฉด
- ์นดํ ๊ณ ๋ฆฌ ๋ฉ๋ด ํ๋ฉด
- ๊ตฌ๋งค ํ๋ฉด
3-1. ์ถ๊ฐ๊ธฐ๋ฅ) ์ฌ์ด์ฆ์ ์ต์ ์ด ์๋ ๋ฉ๋ด์ ์ฐ
- ์ฃผ๋ฌธ ํ๋ฉด
- ์ฃผ๋ฌธ ์๋ฃ ํ๋ฉด
- ์ฃผ๋ฌธ ์ทจ์ ํ๋ฉด
- ์ถ๊ฐ๊ธฐ๋ฅ) ์จ๊ฒจ์ง ๊ธฐ๋ฅ์ผ๋ก ์ด ํ๋งค๊ธ์ก/์ด ํ๋งค์ํ ๋ชฉ๋ก ์ถ๋ ฅ
๋ง๋งํ๊ฒ ์๊ฐํ๋ ์๋ฐ์์ง๋ง, ๋ง์ ํด๋์ค๋ฅผ ๋ค๋ฃจ๊ธฐ ์์ํ๋ ์๋ฐ๋ฅผ ๋ฐฐ์ฐ๊ณ ์ง๋ ์ธ์์ด ์์ด์ ์ธ์ง ์๋ฐ๋ฅผ ์ฒ์ ๋ฐฐ์ฐ๋ ๊ธฐ๋ถ์ด์๋ค.
๋๋ถ์ ์๋ฐ๋ฅผ ๊ธฐ์ด๋ถํฐ ๋ค์ ๋ฐฐ์ฐ๊ณ ์ตํ๋ ๊ฐ์ง ๊ฒฝํ์ด์๋ค.
์์ผ๋ก ๊ณต๋ถํ Spring๋ ๊ฐ์ ๋ง์๊ฐ์ง์ผ๋ก ๊ธฐ์ด๋ถํฐ ํํํ ๋ค์ ธ์ผ๊ฒ ๋ค.
๊ทธ๋ฆฌ๊ณ ์ฝ๋ฉ์ปจ๋ฒค์
์ข ์ตํ์ผ๊ฒ ๋คใ
ใ
๊ธฐ์ต์ด ๊ฐ๋ฌผ๊ฐ๋ฌผํ๋ค