๐ ์ค๋์ ํ์ต ํค์๋
- ํค์ค์คํฌ
๐ฅ KIOSK ๋ฆฌํฉํ ๋ง
Main
๋๋ณด๊ธฐ
package try2;
public class Main {
public static void main(String[] args) {
Kiosk kiosk = new Kiosk();
kiosk.LoadMenu(); // ๋ฆฌ์คํธ ๊ฐ์ ธ์ค๊ธฐ
kiosk.kioskMenu(); // ํค์ค์คํฌ ์์
}
}
- ํค์ค์คํฌ๋ฅผ ๋ถ๋ฌ์ค๋ ๋ฉ์ธํ์ด์ง์ ๋๋ค.
- LoadMenu๋ก ๋ฉ๋ด๋ฆฌ์คํธ๋ฅผ ๋ถ๋ฌ์ค๊ณ ์์ํ๊ฒ ๋ฉ๋๋ค.
Kiosk
๋๋ณด๊ธฐ
package try2;
import java.util.ArrayList;
import java.util.Scanner;
public class Kiosk {
ArrayList<Menu> menuList = new ArrayList<>(); // ๋ฉ์ธ๋ฉ๋ด ๋ฆฌ์คํธ
ArrayList<Product> burgerList = new ArrayList<>(); // ๋ฒ๊ฑฐ ๋ฆฌ์คํธ ์์ฑ
ArrayList<Product> drinkList = new ArrayList<>(); // ์๋ฃ ๋ฆฌ์คํธ ์์ฑ
ArrayList<Product> beerList = new ArrayList<>(); // ๋งฅ์ฃผ ๋ฆฌ์คํธ ์์ฑ
Order order = new Order(); // Order ํด๋์ค์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ ๋ณ์
Scanner scanner = new Scanner(System.in);
public void LoadMenu() { // ๊ฐ๊ฐ ๋ฆฌ์คํธ์ ๋ฉ๋ด๋ฃ๊ธฐ
menuList.add(new Menu("Burgers", "์ต๊ฑฐ์ค ๋นํ ํต์ด์ ๋ค์ ธ๋ง๋ ๋ฒ๊ฑฐ"));
menuList.add(new Menu("Drinks", "๋งค์ฅ์์ ์ง์ ๋ง๋๋ ์๋ฃ"));
menuList.add(new Menu("Beer", "๋ด์ ๋ธ๋ฃจํด๋ฆฐ ๋ธ๋ฃจ์ด๋ฆฌ์์ ์์กฐํ ๋งฅ์ฃผ"));
burgerList.add(new Product("ShackBurger", 6.9, "ํ ๋งํ , ์์์ถ, ์์์ค๊ฐ ํ ํ๋ ์น์ฆ๋ฒ๊ฑฐ"));
burgerList.add(new Product("Cheeseburger", 6.9, "ํฌํ
์ดํ ๋ฒ๊ณผ ๋นํํจํฐ, ์น์ฆ๊ฐ ํ ํ๋ ์น์ฆ๋ฒ๊ฑฐ"));
burgerList.add(new Product("Hamburger", 5.4, "๋นํํจํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ผ์ฑ๊ฐ ๋ค์ด๊ฐ ๊ธฐ๋ณธ๋ฒ๊ฑฐ"));
drinkList.add(new Product("Water", 1.0, "๊ฐ์ฆ๋ ๋ ๋ฌผ!"));
drinkList.add(new Product("Coke", 2.0, "ํ๋ฒ๊ฑฐ์ ์ฝ๋ผ!"));
drinkList.add(new Product("LemonAde", 4.0, "๊ทธ๋ฅ ์ฝ๋ผ๋ง์
๋ผ"));
beerList.add(new Product("SaegMak", 5.0, "์๋งฅ"));
beerList.add(new Product("Cass", 4.0, "์นด์ค"));
beerList.add(new Product("Tera", 4.0, "ํ
๋ผ"));
}
public void kioskMenu() { // ํค์ค์คํฌ ๋ฉ๋ด
showIntro(); // ๋ฐ๋ณต๋๋ ์ธ์ฟ๋ง
showMenu(); // ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
System.out.println();
System.out.println("[ ORDER MENU ]");
System.out.println("4. Order | ์ฅ๋๊ตฌ๋๋ฅผ ํ์ธ ํ ์ฃผ๋ฌธํฉ๋๋ค.");
System.out.println("5. Cancel | ์งํ์ค์ธ ์ฃผ๋ฌธ์ ์ทจ์ํฉ๋๋ค.\n");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int menuChoice = scanner.nextInt();
scanner.nextLine();
switch (menuChoice) {
case 1 -> showBurgerMenu(); // ๋ฒ๊ฑฐ ๋ฉ๋ดํ ๋ณด๊ธฐ
case 2 -> showDrinkMenu(); // ์๋ฃ ๋ฉ๋ดํ ๋ณด๊ธฐ
case 3 -> showBeerMenu(); // ๋งฅ์ฃผ ๋ฉ๋ดํ ๋ณด๊ธฐ
case 4 -> showOrderMenu(); // ์ฅ๋ฐ๊ตฌ๋ ๋ณด๊ธฐ
case 5 -> orderCancel(); // ์ฃผ๋ฌธ ์ทจ์ํ๊ธฐ
default -> System.out.println("1 ~ 5๊น์ง์ ์ซ์๋ง ์
๋ ฅ๊ฐ๋ฅํฉ๋๋ค.");
}
}
public void showIntro() { // ๋ฐ๋ณต๋๋ ์ธ์ฟ๋ง์ ๋ฉ์๋๋ก
System.out.println();
System.out.println("======================================");
System.out.println("\"SHAKESHACK BURGER ์ ์ค์ ๊ฑธ ํ์ํฉ๋๋ค.\"");
System.out.println("์๋ ๋ฉ๋ดํ์ ๋ณด์๊ณ ๋ฉ๋ด๋ฅผ ๊ณจ๋ผ ์
๋ ฅํด์ฃผ์ธ์.\n");
}
public void showMenu() { // ๋ฉ๋ดํ์ดํ ์ ํ
System.out.println("[ SHAKESHACK MENU ]");
for (int i = 0; i < menuList.size(); i++) { // ๋ฉ๋ด๋ฆฌ์คํธ์ size ๋งํผ ๋ฐ๋ณตํด์
Menu menu = menuList.get(i); // menu ์์ ๋ฃ๊ธฐ
System.out.print((i + 1) + ". "); // i๋ 0๋ถํฐ๋๊น +1 ์ ํด์ฃผ์์ต๋๋ค
System.out.printf("%-15s | %s", menu.getName(), menu.getDetail()); // printf ๋ฅผ ์ฌ์ฉํ์ฌ, ๋ฉ๋ด์ด๋ฆ๊ณผ, ์ค๋ช
๋ฃ๊ธฐ
System.out.println(); // ๊ณต๋ฐฑ ์ถ๊ฐ
}
}
public void showBurgerMenu() { // ๋ฒ๊ฑฐ ๋ฆฌ์คํธ ์ถ๋ ฅ
showIntro();
System.out.println("[ Burgers Menu ]");
for (int i = 0; i < burgerList.size(); i++) {
Product product = burgerList.get(i);
System.out.print((i + 1) + ". ");
System.out.printf("%-15s | %s | %s", product.getName(), product.getPrice(), product.getDetail());
System.out.println();
}
System.out.println();
System.out.print("๋ฉ๋ด ์ ํ: ");
int burgerChoice = scanner.nextInt(); // ๋ฒ๊ฑฐ ์ค์์ ์ฃผ๋ฌธํ ๋ฒ๊ฑฐ ์ ํ
scanner.nextLine();
System.out.println();
int burgerInfo = burgerChoice - 1; // ์ฌ์ฉ์๊ฐ ์ ํํ ์ซ์์ ๋ฆฌ์คํธ์ ์ซ์๋ฅผ ๋ง์ถ๊ธฐ ์ํ์ฌ -1
Product selectBurger = burgerList.get(burgerInfo);
System.out.printf("\" %-15s | W %s | %s \"\n", selectBurger.getName(), selectBurger.getPrice(), selectBurger.getDetail());
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์\n");
System.out.print("๋ฉ๋ด ์ ํ: ");
int check = scanner.nextInt();
scanner.nextLine();
System.out.println();
if (check == 1) {
order.addBasket(selectBurger);
System.out.println(selectBurger.getName() + " ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
System.out.println();
} else if (check == 2) {
System.out.println("์ฅ๋ฐ๊ตฌ๋ ์ถ๊ฐ๊ฐ ์ทจ์๋์์ต๋๋ค.");
} else {
System.out.println("์๋ชป๋ ์ซ์๋ฅผ ์
๋ ฅํ์
จ์ต๋๋ค.");
}
kioskMenu();
}
public void showDrinkMenu() { // ์๋ฃ ๋ฆฌ์คํธ ์ถ๋ ฅ
showIntro();
System.out.println("[ Drinks Menu ]");
for (int i = 0; i < drinkList.size(); i++) {
Product product = drinkList.get(i);
System.out.print((i + 1) + ". ");
System.out.printf("%-15s | %s | %s", product.getName(), product.getPrice(), product.getDetail());
System.out.println();
}
System.out.println();
System.out.print("๋ฉ๋ด ์ ํ: ");
int drinkChoice = scanner.nextInt();
scanner.nextLine();
System.out.println();
int drinkInfo = drinkChoice - 1;
Product selectDrink = drinkList.get(drinkInfo);
System.out.printf("\" %-15s | W %s | %s \"\n", selectDrink.getName(), selectDrink.getPrice(), selectDrink.getDetail());
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์\n");
System.out.print("๋ฉ๋ด ์ ํ: ");
int check = scanner.nextInt();
scanner.nextLine();
System.out.println();
if (check == 1) {
order.addBasket(selectDrink);
System.out.println(selectDrink.getName() + " ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
System.out.println();
} else if (check == 2) {
System.out.println("์ฅ๋ฐ๊ตฌ๋ ์ถ๊ฐ๊ฐ ์ทจ์๋์์ต๋๋ค.");
} else {
System.out.println("์๋ชป๋ ์ซ์๋ฅผ ์
๋ ฅํ์
จ์ต๋๋ค.");
}
kioskMenu();
}
public void showBeerMenu() { // ๋น์ด ๋ฆฌ์คํธ ์ถ๋ ฅ
showIntro();
System.out.println("[ Beers Menu ]");
for (int i = 0; i < beerList.size(); i++) {
Product product = beerList.get(i);
System.out.print((i + 1) + ". ");
System.out.printf("%-15s | %s | %s", product.getName(), product.getPrice(), product.getDetail());
System.out.println();
}
System.out.println();
System.out.print("๋ฉ๋ด ์ ํ: ");
int beerChoice = scanner.nextInt();
scanner.nextLine();
System.out.println();
int beerInfo = beerChoice - 1;
Product selcetBeer = beerList.get(beerInfo);
System.out.printf("\" %-15s | W %s | %s \"\n", selcetBeer.getName(), selcetBeer.getPrice(), selcetBeer.getDetail());
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์\n");
System.out.print("๋ฉ๋ด ์ ํ: ");
int check = scanner.nextInt();
scanner.nextLine();
System.out.println();
if (check == 1) {
order.addBasket(selcetBeer);
System.out.println(selcetBeer.getName() + " ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
System.out.println();
} else if (check == 2) {
System.out.println("์ฅ๋ฐ๊ตฌ๋ ์ถ๊ฐ๊ฐ ์ทจ์๋์์ต๋๋ค.");
} else {
System.out.println("์๋ชป๋ ์ซ์๋ฅผ ์
๋ ฅํ์
จ์ต๋๋ค.");
}
kioskMenu();
}
public void showOrderMenu() { // ์ฅ๋ฐ๊ตฌ๋ ๋ณด๊ธฐ
System.out.println("์๋์ ๊ฐ์ด ์ฃผ๋ฌธ ํ์๊ฒ ์ต๋๊น?");
System.out.println();
System.out.println("[ Orders ]");
ArrayList<Product> basket = order.getBasket(); // ๋ฐ์ค์ผ์ ์์ฑํ๊ณ ์ค๋ํด๋์ค์์ ์๋ ๋ฐ์ค์ผ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ
for (int i = 0; i < basket.size(); i++) {
Product menu = basket.get(i);
System.out.printf("\" %-15s | W %s | %s \"\n", menu.getName(), menu.getPrice(), menu.getDetail());
}
System.out.println();
System.out.println("[ Total ]");
System.out.println("W " + order.totalPrice()); // ์ค๋ํด๋์ค์์ ์๋ ์ด๊ธ์ก ๊ฐ์ ธ์ค๊ธฐ
System.out.println();
System.out.println("1. ์ฃผ๋ฌธ 2. ๋ฉ๋ดํ\n");
System.out.print("๋ฉ๋ด ์ ํ: ");
int check = scanner.nextInt();
scanner.nextLine();
if (check == 1) {
orderComplete();
} else if (check == 2) {
System.out.println("๋ฉ๋ดํ์ผ๋ก ๋์๊ฐ๋๋ค.");
kioskMenu();
}
}
public void orderComplete() {
int orderNumber = order.getOrderNumber();
System.out.println("์ฃผ๋ฌธ์ด ์๋ฃ๋์์ต๋๋ค.\n");
System.out.println("๋๊ธฐ๋ฒํธ๋ [ " + orderNumber + " ] ๋ฒ ์
๋๋ค.");
System.out.println("(3์ด ํ ๋ฉ๋ดํ์ผ๋ก ๋์๊ฐ๋๋ค.)");
try { // 3์ด ๋์ ๋ฉ์ถ๊ธฐ ์ํด์ sleep ์ฌ์ฉ์ ์ํด์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํจ
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println();
order.clearBasket(); // ์ฃผ๋ฌธ ํ ์ฅ๋ฐ๊ตฌ๋ ๋น์ฐ๊ธฐ
order.setOrderNumber(orderNumber + 1); // ์ฃผ๋ฌธ๋ฒํธ 1 ๋๋ฆฌ๊ธฐ
kioskMenu(); // ๋ฉ์ธ๋ฉ๋ดํ๋ฉด์ผ๋ก ๋์๊ฐ๊ธฐ
}
public void orderCancel() {
System.out.println();
System.out.println("์งํํ๋ ์ฃผ๋ฌธ์ ์ทจ์ํ์๊ฒ ์ต๋๊น?\n");
System.out.println("1. ํ์ธ 2. ์ทจ์\n");
System.out.print("๋ฉ๋ด ์ ํ:");
int cancelNum = scanner.nextInt();
scanner.nextLine();
if (cancelNum == 1) {
order.clearBasket(); // ์ฅ๋ฐ๊ตฌ๋ ๋น์ฐ๊ธฐ
System.out.println("\n์งํํ๋ ์ฃผ๋ฌธ์ด ์ทจ์๋์์ต๋๋ค.\n");
} else if (cancelNum == 2) {
System.out.println("\n์ฃผ๋ฌธ์ ์ ์งํ๊ณ ๋ฉ๋ดํ์ผ๋ก ๋์๊ฐ๋๋ค.");
}
kioskMenu(); // ๋ฉ์ธ๋ฉ๋ด๋ก ๋์๊ฐ๊ธฐ
}
}
Menu
๋๋ณด๊ธฐ
package try2;
public class Menu {
private String name; // ์ํ ์ด๋ฆ
private String detail; // ์ํ ์ค๋ช
public Menu(String name, String detail) {
this.name = name;
this.detail = detail;
}
public String getName() {
return name;
}
public String getDetail() {
return detail;
}
}
Product
๋๋ณด๊ธฐ
package try2;
public class Product extends Menu {
private double price;
public Product(String name, double price, String detail) {
super(name, detail);
this.price = price;
}
public double getPrice() {
return price;
}
}
Order
๋๋ณด๊ธฐ
package try2;
import java.util.ArrayList;
public class Order {
ArrayList<Product> basket = new ArrayList<>(); // ์ฅ๋ฐ๊ตฌ๋
private int orderNumber; // ์ฃผ๋ฌธ๋ฒํธ
public Order() {
orderNumber = 1; // ์ฃผ๋ฌธ๋ฒํธ 1๋ก ์ด๊ธฐํ
}
public ArrayList<Product> getBasket() { // ์ฅ๋ฐ๊ตฌ๋ ๊ฐ์ ธ์ค๊ธฐ
return basket;
}
public int getOrderNumber() { // ์ฃผ๋ฌธ๋ฒํธ ๊ฐ์ ธ์ค๊ธฐ
return orderNumber;
}
public void setOrderNumber(int orderNumber) { // ์ฃผ๋ฌธ๋ฒํธ
this.orderNumber = orderNumber;
}
public void addBasket(Product menu) {
basket.add(menu);
}
public void clearBasket() {
basket.clear();
}
public double totalPrice() {
double total = 0;
for (Product menu : basket) {
total += menu.getPrice();
}
return total;
}
}
๐ ์ค๋์ ํ๊ณ
ํด๋์ค๋ฅผ ํ์ฉํ์ฌ ๋๋์ด ๋ณด์์ง๋ง, ์์ง๊น์ง ๋ค๋ฅธ ๊ฒ์ผ๋ก ์์ฉ์ ํ ์ ์์์ง๋ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๊ณผ์ ์ดํ ํํ๋ก์ ํธ๊ฐ ์์๋์ด ๊ฐ์ธ๊ณต๋ถ๋ฅผ ๋ง์ด ๋ชปํ์ต๋๋ค.
์ ์ ๋ฒ๊ฑฐ์์ง๋๋ค.
ํ.. ๋ ๋นก์ธ๊ฒ ๊ณต๋ถ๋ฅผ ํด์ผ๊ฒ ์ด์
๋ด์ผ๋.. ํ์ดํ