-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[앨런] 치킨집 미션 제출합니다. #7
base: master
Are you sure you want to change the base?
Changes from all commits
76cb07e
289c02e
33e6dcf
fdf188f
a958cc5
a69a8b4
db5669f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
# java-chicken-2019 | ||
# 시나리오 | ||
0. 기능을 입력받는다. | ||
1. 주문등록 | ||
- 테이블을 보여주고 입력받는다. | ||
- 등록된 테이블을 골라야한다. | ||
- 메뉴를 보여주고 메뉴 번호를 입력받는다. | ||
- 등록된 메뉴 번호여야 한다. | ||
- 메뉴의 수량을 입력받는다. | ||
- 기존 수량 + 입력한 수량 값이 99를 넘지 않는다. | ||
2. 결제하기 | ||
- 테이블을 보여주고 테이블을 입력받는다. | ||
- 주문이 있는 테이블을 골라야한다. | ||
- 주문내역을 보여주고, 결제 방식을 입력받는다. | ||
- 치킨은 10마리당 만원씩 할인된다. | ||
- 추가로 현금결제시 5% 할인된다. | ||
- 최종 결제금액을보여준다. | ||
3. 게임 종료 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
import domain.Menu; | ||
import domain.MenuRepository; | ||
import domain.Table; | ||
import domain.TableRepository; | ||
import java.util.Scanner; | ||
|
||
import controller.ChickenController; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
import java.util.List; | ||
|
||
public class Application { | ||
// TODO 구현 진행 | ||
public static void main(String[] args) { | ||
final List<Table> tables = TableRepository.tables(); | ||
OutputView.printTables(tables); | ||
|
||
final int tableNumber = InputView.inputTableNumber(); | ||
|
||
final List<Menu> menus = MenuRepository.menus(); | ||
OutputView.printMenus(menus); | ||
} | ||
public static void main(String[] args) { | ||
new ChickenController(new InputView(new Scanner(System.in)), new OutputView()).run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package controller; | ||
|
||
import domain.PosMenu; | ||
import domain.payment.PaymentType; | ||
import domain.table.Table; | ||
import domain.table.TableRepository; | ||
import domain.table.Tables; | ||
import domain.table.order.OrderCount; | ||
import domain.table.order.menu.Menu; | ||
import domain.table.order.menu.MenuRepository; | ||
import domain.table.order.menu.Menus; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
public class ChickenController { | ||
private final InputView inputView; | ||
private final OutputView outputView; | ||
|
||
public ChickenController(InputView inputView, OutputView outputView) { | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
} | ||
|
||
public void run() { | ||
outputView.printMain(); | ||
|
||
Menus menus = new Menus(MenuRepository.menus()); | ||
Tables tables = new Tables(TableRepository.tables()); | ||
|
||
while (true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😉 |
||
int function = inputView.inputSelectFunction(); | ||
PosMenu posMenu = PosMenu.of(function); | ||
if (PosMenu.ORDER == posMenu) { | ||
outputView.printTables(tables); | ||
Table table = tables.findTable(inputView.inputTableNumber()); | ||
|
||
outputView.printMenus(menus); | ||
Menu menu = menus.findMenu(inputView.inputSelectMenu()); | ||
|
||
OrderCount orderCount = OrderCount.of(inputView.inputMenuAmount()); | ||
|
||
table.addOrder(menu, orderCount); | ||
} else if (PosMenu.PAYMENT == posMenu) { | ||
outputView.printTables(tables); | ||
Table table = tables.findOrderedTable(inputView.inputTableNumber()); | ||
|
||
outputView.printOrderHistory(table); | ||
PaymentType paymentType = PaymentType.of(inputView.inputSelectPayment(table)); | ||
|
||
long price = paymentType.calculatePrice(table.getOrder()); | ||
outputView.printPrice(price); | ||
|
||
table.clear(); | ||
} else if (PosMenu.EXIT == posMenu) { | ||
System.exit(0); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수(또는메서드)의 길이가 15라인을 넘어가지 않도록 구현한다.
|
||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum PosMenu { | ||
ORDER(1), | ||
PAYMENT(2), | ||
EXIT(3); | ||
|
||
private final int function; | ||
|
||
PosMenu(int function) { | ||
this.function = function; | ||
} | ||
|
||
public static PosMenu of(int functionNumber) { | ||
return Arrays.stream(values()) | ||
.filter(posMenu -> posMenu.function == functionNumber) | ||
.findAny() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. findFirst()가 더 좋지 않을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1개의 요소를 찾을때라서 순서가 상관없는데요. |
||
.orElseThrow(() -> new IllegalArgumentException("찾을 수 없는 메뉴입니다. functionNumber=" + functionNumber)); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package domain.payment; | ||
|
||
import domain.table.order.Order; | ||
|
||
public class CacheDiscountStrategy implements DiscountStrategy { | ||
private static final double DISCOUNT_RATE = 0.95; | ||
|
||
@Override | ||
public long calculate(long money, Order order) { | ||
return (long)((double)money * DISCOUNT_RATE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package domain.payment; | ||
|
||
import domain.table.order.Order; | ||
|
||
public class ChickenDiscountStrategy implements DiscountStrategy { | ||
private static final int DISCOUNT_PRICE = 10000; | ||
|
||
@Override | ||
public long calculate(long money, Order order) { | ||
int count = order.calculateChickenCount(); | ||
int discount = (count / 10) * DISCOUNT_PRICE; | ||
return discount; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package domain.payment; | ||
|
||
import domain.table.order.Order; | ||
|
||
public interface DiscountStrategy { | ||
long calculate(long money, Order order); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package domain.payment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import domain.table.order.Order; | ||
|
||
public enum PaymentType { | ||
CARD(1, Arrays.asList(new ChickenDiscountStrategy())), | ||
CACHE(2, Arrays.asList(new ChickenDiscountStrategy()), Arrays.asList(new CacheDiscountStrategy())); | ||
|
||
private final int type; | ||
private final List<DiscountStrategy> totalDiscountStrategies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제 생각에는 PaymentType에서 totalDiscountStrategies를 가지는 것보다 afterDiscountStrategies만 가지고 있는 편이 좋을 것 같다는 생각이 드는데 이 의견에 대해서는 어떻게 생각하시나요? PaymentType에 따라서 totalDiscountStrategies가 바뀌는게 아닐 것 같아서요. |
||
private final List<DiscountStrategy> afterDiscountStrategies; | ||
|
||
PaymentType(int type, List<DiscountStrategy> totalDiscountStrategies) { | ||
this.type = type; | ||
this.totalDiscountStrategies = totalDiscountStrategies; | ||
this.afterDiscountStrategies = new ArrayList<>(); | ||
} | ||
|
||
PaymentType(int type, List<DiscountStrategy> totalDiscountStrategies, | ||
List<DiscountStrategy> afterDiscountStrategies) { | ||
this.type = type; | ||
this.totalDiscountStrategies = totalDiscountStrategies; | ||
this.afterDiscountStrategies = afterDiscountStrategies; | ||
} | ||
|
||
public static PaymentType of(int type) { | ||
return Arrays.stream(values()) | ||
.filter(paymentType -> paymentType.type == type) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("찾을 수 없는 결제방식입니다. type =" + type)); | ||
} | ||
|
||
public long calculatePrice(Order order) { | ||
long money = order.calculateTotalMoney(); | ||
money = preDiscount(order, money); | ||
return afterDiscount(order, money); | ||
} | ||
|
||
private long afterDiscount(Order order, long money) { | ||
for (DiscountStrategy discountStrategy : afterDiscountStrategies) { | ||
money = discountStrategy.calculate(money, order); | ||
} | ||
return money; | ||
} | ||
Comment on lines
+37
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 |
||
|
||
private long preDiscount(Order order, long money) { | ||
long weight = 0; | ||
|
||
for (DiscountStrategy discountStrategy : totalDiscountStrategies) { | ||
weight += discountStrategy.calculate(money, order); | ||
} | ||
|
||
money -= weight; | ||
return money; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package domain.table; | ||
|
||
import domain.table.order.Order; | ||
import domain.table.order.OrderCount; | ||
import domain.table.order.menu.Menu; | ||
|
||
public class Table { | ||
private final int number; | ||
private final Order order; | ||
|
||
public Table(final int number, Order order) { | ||
this.number = number; | ||
this.order = order; | ||
} | ||
|
||
public void addOrder(Menu menu, OrderCount orderCount) { | ||
order.add(menu, orderCount); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Integer.toString(number); | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public Order getOrder() { | ||
return order; | ||
} | ||
|
||
public void clear() { | ||
order.clear(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return order.isEmpty(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하핫....말 안해도...아시죠??😂😂
depth, indent...화이팅 하십쇼!!!