๐ ์ค๋์ ํ์ต ํค์๋
- ํค์ค์คํฌ
๐ฅ KIOSK
package try1;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String menuTitle = "\"SHAKESHACK BURGER ์ ์ค์ ๊ฑธ ํ์ํฉ๋๋ค.\"\n" +
"์๋ ๋ฉ๋ดํ์ ๋ณด์๊ณ ๋ฉ๋ด๋ฅผ ๊ณจ๋ผ ์
๋ ฅํด์ฃผ์ธ์.\n";
ArrayList<String> Menu = new ArrayList<>();
Menu.add("Burgers | ์ต๊ฑฐ์ค ๋นํ ํต์ด์ ๋ค์ ธ๋ง๋ ๋ฒ๊ฑฐ");
Menu.add("Drinks | ๋งค์ฅ์์ ์ง์ ๋ง๋๋ ์๋ฃ");
Menu.add("Beer | ๋ด์ ๋ธ๋ฃจํด๋ฆฐ ๋ธ๋ฃจ์ด๋ฆฌ์์ ์์กฐํ ๋งฅ์ฃผ");
ArrayList<String> burgerMenu = new ArrayList<>();
burgerMenu.add("ShackBurger | W 6.9 | ํ ๋งํ , ์์์ถ, ์์์ค๊ฐ ํ ํ๋ ์น์ฆ๋ฒ๊ฑฐ");
burgerMenu.add("Cheeseburger | W 6.9 | ํฌํ
์ดํ ๋ฒ๊ณผ ๋นํํจํฐ, ์น์ฆ๊ฐ ํ ํ๋ ์น์ฆ๋ฒ๊ฑฐ");
burgerMenu.add("Hamburger | W 5.4 | ๋นํํจํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ผ์ฑ๊ฐ ๋ค์ด๊ฐ ๊ธฐ๋ณธ๋ฒ๊ฑฐ");
ArrayList<String> drinkMenu = new ArrayList<>();
drinkMenu.add("CoKe | W 3.5 | ๋๋ฝ๊ฒ ๋น์ผ ์ฝ๋ผ");
drinkMenu.add("LemonAde | W 4.5 | ๋๋ฝ๊ฒ ๋น์ผ ๋ ๋ชฌ์์ด๋");
drinkMenu.add("Shake | W 6.5 | ๊ฐํ์ ์ฐ์ด๋จน๋ ๋ฐํฌ์์ดํฌ");
ArrayList<String> beerMenu = new ArrayList<>();
beerMenu.add("Beer | W 5.0 | ํ๋ฒ๊ฑฐ์ ๋งฅ์ฃผ?");
beerMenu.add("Cass | W 4.5 | ํ๋ฒ๊ฑฐ์ ๋งฅ์ฃผ?");
beerMenu.add("Tera | W 4.5 | ํ๋ฒ๊ฑฐ์ ๋งฅ์ฃผ?");
ArrayList<String> basket = new ArrayList<>();
int WaitNum = 1;
while (true) {
System.out.println(menuTitle);
System.out.println("[ SHACKSHACK MENU ]");
for (int i = 0; i < Menu.size(); i++) {
System.out.println((i + 1) + ". " + Menu.get(i));
}
System.out.println();
System.out.println("[ ORDER MENU ]");
System.out.println("4. Order | ์ฅ๋ฐ๊ตฌ๋๋ฅผ ํ์ธ ํ ์ฃผ๋ฌธํฉ๋๋ค.");
System.out.println("5. Cancel | ์งํ์ค์ธ ์ฃผ๋ฌธ์ ์ทจ์ํฉ๋๋ค.");
System.out.println("6. Exit | ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.\n");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํ์ธ์: ");
int menuChoice = scanner.nextInt();
scanner.nextLine();
System.out.println();
if (menuChoice == 1) { // ํ๋ฒ๊ฑฐ ์ ํ
System.out.println(menuTitle);
System.out.println("[ Burgers MENU ]");
for (int i = 0; i < burgerMenu.size(); i++) {
System.out.println((i + 1) + ". " + burgerMenu.get(i));
}
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int burgerChoice = scanner.nextInt();
System.out.println();
if (burgerChoice == 1) { // ํ๋ฒ๊ฑฐ ์ข
๋ฅ ์ ํ
System.out.println("\"" + burgerMenu.get(0) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("ShackBurger ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(burgerMenu.get(0));
System.out.println();
}
} else if (burgerChoice == 2) {
System.out.println("\"" + burgerMenu.get(1) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("Cheeseburger ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(burgerMenu.get(1));
System.out.println();
}
} else if (burgerChoice == 3) {
System.out.println("\"" + burgerMenu.get(2) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("Hamburger ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(burgerMenu.get(2));
System.out.println();
}
}
}
if (menuChoice == 2) { // ์๋ฃ์ ์ ํ
System.out.println(menuTitle);
System.out.println("[ Drinks MENU ]");
for (int i = 0; i < drinkMenu.size(); i++) {
System.out.println((i + 1) + ". " + drinkMenu.get(i));
}
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int drinkChoice = scanner.nextInt();
System.out.println();
if (drinkChoice == 1) { // ์๋ฃ์ ์ข
๋ฅ ์ ํ
System.out.println("\"" + drinkMenu.get(0) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("CoKe ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(drinkMenu.get(0));
System.out.println();
}
} else if (drinkChoice == 2) {
System.out.println("\"" + drinkMenu.get(1) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("LemonAde ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(drinkMenu.get(1));
System.out.println();
}
} else if (drinkChoice == 3) {
System.out.println("\"" + drinkMenu.get(2) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("Shake ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(drinkMenu.get(2));
System.out.println();
}
}
}
if (menuChoice == 3) { // ์ฃผ๋ฅ ์ ํ
System.out.println(menuTitle);
System.out.println("[ Beers MENU ]");
for (int i = 0; i < beerMenu.size(); i++) {
System.out.println((i + 1) + ". " + beerMenu.get(i));
}
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int beerChoice = scanner.nextInt();
System.out.println();
if (beerChoice == 1) { // ์ฃผ๋ฅ ์ข
๋ฅ ์ ํ
System.out.println("\"" + beerMenu.get(0) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("SoJu ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(beerMenu.get(0));
System.out.println();
}
} else if (beerChoice == 2) {
System.out.println("\"" + beerMenu.get(1) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("Cass ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(beerMenu.get(1));
System.out.println();
}
} else if (beerChoice == 3) {
System.out.println("\"" + beerMenu.get(2) + "\"");
System.out.println("์ ๋ฉ๋ด๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int martChoice = scanner.nextInt();
System.out.println();
if (martChoice == 1) {
System.out.println("Tera ๊ฐ ์ฅ๋ฐ๊ตฌ๋์ ์ถ๊ฐ๋์์ต๋๋ค.");
basket.add(beerMenu.get(2));
System.out.println();
}
}
}
if (menuChoice == 4) {
System.out.println("์๋์ ๊ฐ์ด ์ฃผ๋ฌธ ํ์๊ฒ ์ต๋๊น?\n");
System.out.println("[ Orders ]");
for (String a : basket) {
System.out.println(a);
}
System.out.println();
System.out.println("[ Total ]");
double total = 0;
for (int i = 0; i < basket.size(); i++) {
String cash = basket.get(i).substring(18, 21);
Double money = Double.parseDouble(cash);
total += money;
}
System.out.println("W " + total);
System.out.println();
System.out.println("1. ์ฃผ๋ฌธ 2. ๋ฉ๋ดํ");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํ์ธ์: ");
int orderChoice = scanner.nextInt();
scanner.nextLine();
if (orderChoice == 1) {
System.out.println("์ฃผ๋ฌธ์ด ์๋ฃ๋์์ต๋๋ค!\n");
System.out.println("๋๊ธฐ๋ฒํธ๋ [ " + WaitNum + " ] ๋ฒ ์
๋๋ค");
System.out.println("(3์ดํ ๋ฉ๋ดํ์ผ๋ก ๋์๊ฐ๋๋ค.)\n");
WaitNum++;
basket.clear();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (menuChoice == 5) {
System.out.println("์งํํ๋ ์ฃผ๋ฌธ์ ์ทจ์ํ๊ธฐ์
์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int cancelChoice = scanner.nextInt();
if (cancelChoice == 1) {
basket.clear();
System.out.println("์งํํ๋ ์ฃผ๋ฌธ์ด ์ทจ์๋์์ต๋๋ค.");
}
}
if (menuChoice == 6) {
System.out.println("ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํ์๊ฒ ์ต๋๊น?");
System.out.println("1. ํ์ธ 2. ์ทจ์\n");
System.out.print("๋ฉ๋ด๋ฅผ ์ ํํด์ฃผ์ธ์: ");
int exitChoice = scanner.nextInt();
if (exitChoice == 1) {
break;
}
}
}
}
}
๐ ์ค๋์ ํ๊ณ
ํด๋์ค๋ฅผ ๋ฐฐ์์ ์ฌ์ฉํ๋ ๊ฒ์ ์์ด์๋ ์ค๋ ์ค๋ ์ธ ์ ์์ ์ค ์์์ง๋ง,
์๊ฐ๋ณด๋จ ์ฝ์ง ์์ต๋๋ค.
์ด๋ค ์์ผ๋ก ๋๋ ์ผ ํ ์ง ๊ฐ์ด ์ ์กํ์ ์ผ๋จ ๊ตฌํ์ด๋ผ๋ ํ ์ ์์์ง ๋ง๋ค์ด ๋ณด์์ต๋๋ค.
๋ฉ์ธ์ ๋๋ ค ๋ฃ์ ์ฝ๋.. ๋ฉ๋์ฝ
300์ค ์ ๋ ๋์๋ค์..
๋ฐฐ์ด์ ๋ค์ด๊ฐ๋ ๋ชจ๋ ๊ฒ๋ค์ String ํ์์ผ๋ก ํ๊ธฐ ๋๋ฌธ์
์ด๊ธ์ก์ ๊ตฌํ๋ ๊ฒ ์ฝ์ง ์์์ ์ด๋ค ์์ผ๋ก ๋นผ์ ๋ํ ์ง ๊ณ ๋ฏผํ๋ ์์ค
๊ทธ ๋ถ๋ถ์ ๋ฌธ์์ด์ ๋นผ๋ด์, ๋นผ๋ธ ๋ฌธ์์ด์ ๋๋ธ๋ก ๋ณํํด์ ์ฐ๋ฉด ๋๊ฒ ๋ค ์๊ฐ์ด ๋ค์ด์
substring์ผ๋ก ๋นผ๋ด๊ณ Double.parseDouble๋ก ๊ฐ์ ํ๋ณํ์ ์์ผ์ ์ด๊ธ์ก์ ๊ตฌํ์ต๋๋ค.
์ด์ ํด๋์ค๋ก ๋๋๋ ๊ณผ์ ์ ํตํด์ ํด๋์ค๋ฅผ ๋ ์ดํดํ๊ณ ํ์ฉํ๋ฉด์
์ฑ์ฅํด ๋ณด๊ฒ ์ต๋๋ค.