diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..c3f502a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml +# 에디터 기반 HTTP 클라이언트 요청 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..29cba1f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ece9f84 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..7579af0 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,27 @@ +## 입/출력 +- [x] 음료 자판기 시작 안내 출력 +- [x] 진행 위한 입력 받기 +- [x] 차가운/따뜻한 음료 택1 안내 출력 +- [x] 차가운/따뜻한 음료 택1 입력 받기 +- [x] 위에서 선택한 음료 메뉴 출력 +- [x] 사용자의 구매 음료 입렫 받기 +- [x] 결제 방식 출력 +- [x] 사용자의 결제 방식 입력 받기 +- 카드 결제시 + - [ ] continue +- 현금 결제시 + - [x] 현금 투입 출력 + - [ ] 음료 메뉴 가격에 따라 반복 + - [x] 현금 투입 입력 받기 + - [ ] 투입 금액 출력 +- [ ] 이용 감사 안내 출력 +- [ ] 주문 음료 출력 +- [ ] 잔돈 출력 +- +## 자판기 +- [x] 음료 메뉴 +- [ ] 현금 결제만 가능 + - [x] 거스름 돈 반환 + - [ ] 돈을 잘못 넣은 경우를 위해 반환 기능 +- [ ] 카드 결제 추가 + - [x] 10% 부가세 추가 결제 \ No newline at end of file diff --git a/src/Application.java b/src/Application.java new file mode 100644 index 0000000..36415ce --- /dev/null +++ b/src/Application.java @@ -0,0 +1,7 @@ +import main.controller.VendingMachineController; + +public class Application { + public static void main(String[] args) { + new VendingMachineController().start(); + } +} \ No newline at end of file diff --git a/src/main/controller/VendingMachineController.java b/src/main/controller/VendingMachineController.java new file mode 100644 index 0000000..4d81703 --- /dev/null +++ b/src/main/controller/VendingMachineController.java @@ -0,0 +1,13 @@ +package main.controller; + +import main.view.OutputView; + +public class VendingMachineController { + public void start() { + set(); + } + + private void set() { + OutputView.printWelcomeMessage(); + } +} diff --git a/src/main/domain/Beverage.java b/src/main/domain/Beverage.java new file mode 100644 index 0000000..1b7bff0 --- /dev/null +++ b/src/main/domain/Beverage.java @@ -0,0 +1,4 @@ +package main.domain; + +public record Beverage(String name, int price) { +} diff --git a/src/main/domain/Cash.java b/src/main/domain/Cash.java new file mode 100644 index 0000000..6df7c34 --- /dev/null +++ b/src/main/domain/Cash.java @@ -0,0 +1,17 @@ +package main.domain; + +import java.util.Arrays; + +public class Cash implements Payment{ + private int cashInput = 0; + + public void injectionCash(int inputOption) { + Arrays.stream(CashDenomination.values()) + .filter(denomination -> denomination.getOption() == inputOption) + .forEach(denomination -> cashInput += denomination.getValue()); + } + + private int calculateChange(int price) { + return price - cashInput; + } +} diff --git a/src/main/domain/CashDenomination.java b/src/main/domain/CashDenomination.java new file mode 100644 index 0000000..6890fcd --- /dev/null +++ b/src/main/domain/CashDenomination.java @@ -0,0 +1,26 @@ +package main.domain; + +public enum CashDenomination { + FIFTY_THOUSAND_WON(1, 50000), + TEN_THOUSAND_WON(2, 10000), + FIVE_THOUSAND_WON(3, 5000), + ONE_THOUSAND_WON(4, 1000), + FIVE_HUNDRED_WON(5, 500), + ONE_HUNDRED_WON(6, 100); + + private final int option; + private final int value; + + CashDenomination(int option, int value) { + this.option = option; + this.value = value; + } + + public int getOption() { + return option; + } + + public int getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/domain/Credit.java b/src/main/domain/Credit.java new file mode 100644 index 0000000..6fdc3de --- /dev/null +++ b/src/main/domain/Credit.java @@ -0,0 +1,14 @@ +package main.domain; + +public class Credit { + private final double FEE = 0.1; + private final int amount; + + public Credit(int price) { + this.amount = price; + } + + public int getPaymentAmount() { + return (int) (amount + amount * FEE); + } +} diff --git a/src/main/domain/Options.java b/src/main/domain/Options.java new file mode 100644 index 0000000..00b1107 --- /dev/null +++ b/src/main/domain/Options.java @@ -0,0 +1,50 @@ +package main.domain; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public enum Options { + COLD("차가운 음료",List.of( + new Beverage("스프라이트 ", 1500), + new Beverage("코카콜라", 1300), + new Beverage("솔의눈 ", 1000), + new Beverage("펩시 콜라 ", 1100) + )), + HOT("따뜻한 음료", List.of( + new Beverage("TOP커피", 1800), + new Beverage("꿀물", 1500), + new Beverage("홍삼차 ", 1700), + new Beverage("단팥죽 ", 2100) + )); + + private static final Map beverageToOptions = new HashMap<>(); + + static { + for (Options menu : Options.values()) { + for (Beverage food : menu.beverages) { + beverageToOptions.put(food.name(), menu); + } + } + } + + private final String options; + private final List beverages; + + Options(String options, List beverages) { + this.options = options; + this.beverages = beverages; + } + + public static Options getUserSelectedOption(int userInput) { + return Options.values()[userInput - 1]; + } + + public String getOptions() { + return options; + } + + public List getBeverages() { + return beverages; + } +} diff --git a/src/main/domain/Payment.java b/src/main/domain/Payment.java new file mode 100644 index 0000000..05e1043 --- /dev/null +++ b/src/main/domain/Payment.java @@ -0,0 +1,4 @@ +package main.domain; + +public interface Payment { +} diff --git a/src/main/view/InputView.java b/src/main/view/InputView.java new file mode 100644 index 0000000..9498a1f --- /dev/null +++ b/src/main/view/InputView.java @@ -0,0 +1,30 @@ +package main.view; + +import java.util.Scanner; + +public class InputView { + private static final Scanner scanner = new Scanner(System.in); + + public static String readContinueStatus(Scanner scanner) { + System.out.println("계속 하려면 아무키나 입력하세요 ..."); + return scanner.nextLine(); + } + + public static int readBeverageOption(Scanner scanner) { + System.out.print("사용자 입력 >"); + return scanner.nextInt(); + } + + public static int readBeverageNumber(Scanner scanner) { + System.out.print("사용자 입력 >"); + return scanner.nextInt(); + } + + public static int getPaymentOption(Scanner scanner) { + return scanner.nextInt(); + } + + public static int getCashOption(Scanner scanner) { + return scanner.nextInt(); + } +} \ No newline at end of file diff --git a/src/main/view/OutputView.java b/src/main/view/OutputView.java new file mode 100644 index 0000000..5d3c4e4 --- /dev/null +++ b/src/main/view/OutputView.java @@ -0,0 +1,68 @@ +package main.view; + +import main.domain.Beverage; +import main.domain.CashDenomination; +import main.domain.Options; + +import java.util.List; + +public class OutputView { + + public static void printException(Exception exception) { + System.out.println(exception.getMessage()); + } + + public static void printWelcomeMessage() { + System.out.println("[어서와요! GDSC 음료 자판기]"); + System.out.println(); + } + + public static void printOptionsSelection() { + System.out.println("음료를 선택 해주세요!"); + } + + public static void printOptions() { + System.out.println("음료를 선택 해주세요!"); + System.out.println(); + + for (Options option : Options.values()) { + System.out.println("[" + (option.ordinal() + 1) + "] " + option.getOptions()); + } + + System.out.println(); + } + + public void printBeverages(int optionNumber) { + Options selectedOption = getOptionByNumber(optionNumber); + + List beverages = selectedOption.getBeverages(); + + for (int i = 0; i < beverages.size(); i++) { + Beverage beverage = beverages.get(i); + System.out.printf("[%d] %s : %d원\n", i + 1, beverage.name(), beverage.price()); + } + } + + public void printCashDenomination() { + + for (CashDenomination denomination : CashDenomination.values()) { + System.out.println("[" + denomination.getOption() + "] " + denomination.getValue() + "원"); + } + System.out.println("[0] 반환"); + } + + private Options getOptionByNumber(int optionNumber) { + return Options.values()[optionNumber - 1]; + } + + public static void printPaymentOptions() { + lineClassification(); + System.out.println("[결제 방식 선택]\n"); + System.out.println("[1] 현금"); + System.out.println("[2] 카드 (부가세 10% 적용)"); + } + + public static void lineClassification() { + System.out.println("------------------------------"); + } +} diff --git a/vending-machine.iml b/vending-machine.iml new file mode 100644 index 0000000..b054cc0 --- /dev/null +++ b/vending-machine.iml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file