-
Notifications
You must be signed in to change notification settings - Fork 0
[우테코 스터디] 로또 다시 구현하기 #1
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
base: review
Are you sure you want to change the base?
Changes from all commits
6c7a96d
30a006a
e3ec6a2
6464421
4237548
b6b7dd5
b59e2da
6b2b920
b51406f
b5e1cff
4a3c8db
328ea43
c1f4bf8
6ae0035
d9cd286
03cb4f5
25899e5
1bb4cd7
f4943c4
a286cfc
bd8d4b9
27a258f
b771a16
26ef7b2
6b3b3f9
2e0ea5c
ad80c86
14650ef
732e159
0f79b81
e247daa
07b2974
9b66531
cd1d4ca
3d59a8c
bc20677
90c1edf
db0d3bb
a61eb34
6c30c61
c42cb60
b0e07b8
1ddce8f
f05b992
2303ec1
cae0e80
6642614
8276e3c
8950e6d
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,67 @@ | ||
| # javascript-lotto-precourse | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| # ✅ 구현할 기능 목록 | ||
|
|
||
| 간단한 로또 발매기를 구현한다. | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [입력] 로또 구입 금액을 입력받는다. | ||
|
|
||
| #### ㄴ validation | ||
|
|
||
| - 예외 상황 시 에러 문구를 출력해야 한다. 단, 에러 문구는 "[ERROR]"로 시작해야 한다. | ||
| - 구입 금액은 1,000원 단위로 입력 받으며 1,000원으로 나우어 떨어지지 않는 경우 예외 처리한다. | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [출력] 발행한 로또 수량 및 번호를 출력한다. 로또 번호는 오름차순으로 정렬하여 보여준다. | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [입력] 당첨번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다. | ||
|
|
||
| #### ㄴ validation | ||
|
|
||
| - 예외 상황 시 에러 문구를 출력해야 한다. 단, 에러 문구는 "[ERROR]"로 시작해야 한다. | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [입력] 보너스 번호를 입력 받는다. | ||
|
|
||
| #### ㄴ validation | ||
|
|
||
| - 예외 상황 시 에러 문구를 출력해야 한다. 단, 에러 문구는 "[ERROR]"로 시작해야 한다. | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [출력] 당첨 내역을 출력한다. | ||
|
|
||
| <출력 예시> | ||
| 당첨 통계 | ||
|
|
||
| \--- | ||
|
|
||
| 3개 일치 (5,000원) - 1개 | ||
|
|
||
| | ||
|
|
||
| | ||
|
|
||
| ### 🟢 [출력] 총 수익률을 출력한다. | ||
|
|
||
| 수익률은 소수점 둘쨰 자리에서 반올림 한다. (ex. 100.0%, 51.5%, 1,000,000.0%) | ||
|
|
||
| - | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import LottoController from './controller/LottoController.js'; | ||
|
|
||
| class App { | ||
| async run() {} | ||
| async run() { | ||
| await new LottoController().runLotto(); | ||
| } | ||
| } | ||
|
|
||
| export default App; |
|
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. 웹 프론트엔드 3주차 공통 피드백의 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ class Lotto { | |
|
|
||
| #validate(numbers) { | ||
| if (numbers.length !== 6) { | ||
| throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); | ||
| throw new Error('[ERROR] 로또 번호는 6개여야 합니다.'); | ||
|
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. 아래 |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const ERROR_PREFIX = '[ERROR]'; | ||
|
|
||
| const createMsg = (msg) => `${ERROR_PREFIX} ${msg} ${'다시 입력해주세요.'}\n`; | ||
|
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. 다시 입력해주세요. 부분은 일반 문자열이라 ${}밖에 있어도 괜찮을 것 같아요! 🤔 |
||
|
|
||
| const ERROR_MESSAGES = { | ||
|
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. 상수화를 엄청 꼼꼼하게 하셨네요! 👍 |
||
| emptyValue: createMsg('값이 존재하지 않습니다.'), | ||
| regexpTest: createMsg('형식이 잘 못되었습니다.'), | ||
| startComma: createMsg('입력이 콤마(,)부터 시작할 수 없습니다.'), | ||
| endComma: createMsg('입력 끝에 콤마(,)로 끝날 수 없습니다.'), | ||
| enteredMoreFiveTimes: '5회 이상 잘못 입력하여 종료되없습니다. 다시 실행해주세요.', | ||
| limitDigits: createMsg('최소 4자리 숫자부터 6자리 숫자까지 입력 가능합니다.'), | ||
| negativeNumber: createMsg('음수가 입력될 수 없습니다.'), | ||
| thousandUnit: createMsg( | ||
| '로또 금액인 1000원 단위로만 입력 가능하며, 최대 10만원까지 입력 가능합니다.' | ||
| ), | ||
| winningNumberSixDigit: createMsg('당첨번호는 6자리를 입력해야합니다.'), | ||
| isDuplicatedInWinningNumber: createMsg('당첨번호와 중복되는 번호를 입력하셨습니다.'), | ||
| }; | ||
|
|
||
|
Comment on lines
+6
to
+19
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. 우와! 예외 처리 진짜 상세하게 하셨네요! |
||
| export { ERROR_PREFIX, ERROR_MESSAGES }; | ||
|
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.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const INPUT_MESSAGES = { | ||
| whatPurchaseAmount: '구매금액을 입력해주세요. \n => ', | ||
| winningNumber: '당첨번호를 입력해주세요. \n => ', | ||
| bonusNumber: '보너스번호를 입력해주세요. \n => ', | ||
|
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.
|
||
| }; | ||
|
|
||
| export default INPUT_MESSAGES; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const OUTPUT_MESSAGES = { | ||
| purchaseNumber: '개를 구매했습니다.', | ||
| winningStatistics: '당첨 통계\n--- ', | ||
| matchedThree: '3개 일치 (5,000원) - ', | ||
| matchedFour: '4개 일치 (50,000원) - ', | ||
| matchedFive: '5개 일치 (1,500,000원) - ', | ||
| matchedFiveBonus: '5개 일치, 보너스 볼 일치 (30,000,000원) - ', | ||
| matchedSix: '6개 일치 (2,000,000,000원) - ', | ||
| printQuantity: '개', | ||
| totalReturn: '총 수익률은 ', | ||
| totalReturnPercentage: '% 입니다.', | ||
| }; | ||
|
Comment on lines
+2
to
+12
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. 상수처리를 하는 이유가 유지보수와 가독성 때문이라고 알고 있는데, |
||
|
|
||
| export default OUTPUT_MESSAGES; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import InputPurchaseModule from '../modules/InputPurchaseModule.js'; | ||
| import InputWinningModule from '../modules/InputWinningModule.js'; | ||
| import InputBonusModule from '../modules/InputBonusModule.js'; | ||
| import PrintWinningDetails from '../modules/printWinningDetails.js'; | ||
|
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. 보람님의 로또 프로젝트를 실행을 해봤는데, 에러가 납니다. LottoController.js파일 import부분 이 부분에 파일명은 대문자로 시작을 해서 연결이 안되었네요! vscode환경에서는 대소문자는 허용되는 경우가 있어서, 최종 코테 과제 제출하실 때 꼼꼼히 확인해보시면 좋을 것 같아요~ |
||
| import PrintRandomNumber from '../modules/PrintRandomNumber.js'; | ||
|
|
||
| class LottoController { | ||
| constructor() { | ||
| this.inputPurchaseModule = new InputPurchaseModule(); | ||
| this.inputWinningModule = new InputWinningModule(); | ||
| this.printRandomNumber = new PrintRandomNumber(); | ||
| } | ||
|
|
||
| async runLotto() { | ||
| const purchasPrice = await this.inputPurchaseModule.inputPurchaseAmount(); | ||
| const purchasQuantity = purchasPrice / 1000; | ||
|
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장 단위가 1000원이라 이 부분은 상수처리해도 좋겠다는 생각이 듭니다 :) |
||
| const lottoNumber = this.printRandomNumber.printRandomNumber(purchasQuantity); | ||
| const winningNumber = await this.inputWinningModule.inputWinningNumber(); | ||
| const inputBonusModule = new InputBonusModule(winningNumber); | ||
| const bonusNumber = await inputBonusModule.inputBonusNumber(); | ||
| const printWinningDetails = new PrintWinningDetails(purchasPrice); | ||
| printWinningDetails.winningDetails(lottoNumber, winningNumber, bonusNumber); | ||
| } | ||
| } | ||
|
|
||
| export default LottoController; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import App from "./App.js"; | ||
| import App from './App.js'; | ||
|
|
||
| const app = new App(); | ||
| await app.run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { ERROR_MESSAGES } from '../constants/errorMessages.js'; | ||
| import validation from '../validation/validation.js'; | ||
| import InputView from '../view/InputView.js'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class InputBonusModule { | ||
| constructor(winningNumber) { | ||
| this.validation = new validation(); | ||
| this.winningNumber = winningNumber; | ||
| } | ||
|
|
||
| async inputBonusNumber() { | ||
| const validatedBonusNumber = await this.repeatInput(); | ||
| const changeTypeNumber = Number(validatedBonusNumber); | ||
| OutputView.printSpace(); | ||
| return changeTypeNumber; | ||
| } | ||
|
|
||
| async inputAndValidation() { | ||
| const input = await InputView.readBonusNumber(); | ||
| const winningNumber = this.winningNumber; | ||
| this.validateBonusNumber(input, winningNumber); | ||
| return input; | ||
| } | ||
|
|
||
| validateBonusNumber(value, winningNumber) { | ||
| this.validation.empty(value); | ||
| const regExpPattern = /\d{1,2}/; | ||
| this.validation.regularExpression(value, regExpPattern); | ||
| this.validation.isDuplicatedInWinningNumber(value, winningNumber); | ||
| } | ||
|
|
||
| async errorCatch() { | ||
| try { | ||
| const validatedInput = await this.inputAndValidation(); | ||
| return validatedInput; | ||
| } catch (error) { | ||
| OutputView.printError(error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| async repeatInput() { | ||
| for (let i = 0; i < 10; i++) { | ||
| const vlaidatedInput = await this.errorCatch(); | ||
| if (vlaidatedInput) return vlaidatedInput; | ||
| if (i === 5) throw new Error(ERROR_MESSAGES.enteredMoreFiveTimes); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default InputBonusModule; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { ERROR_MESSAGES } from '../constants/errorMessages.js'; | ||
| import validation from '../validation/validation.js'; | ||
| import InputView from '../view/InputView.js'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class InputPurchaseModule { | ||
| constructor() { | ||
| this.validation = new validation(); | ||
| } | ||
|
|
||
| async inputPurchaseAmount() { | ||
| const validatedPurchaseAmount = await this.repeatInput(); | ||
| const changgeTypeNumber = Number(validatedPurchaseAmount); | ||
| OutputView.printSpace(); | ||
| return changgeTypeNumber; | ||
| } | ||
|
|
||
| async inputAndValidation() { | ||
| const input = await InputView.readPurchaseAmount(); | ||
| this.validatatePrice(input); | ||
| return input; | ||
| } | ||
|
|
||
| validatatePrice(value) { | ||
| this.validation.empty(value); | ||
| const regExpPattern = /\d/; | ||
| this.validation.regularExpression(value, regExpPattern); | ||
| this.validation.nagativeNumber(value); | ||
| this.validation.limitDigits(value); | ||
| this.validation.thousandUnit(value); | ||
| } | ||
|
|
||
| async errorCatch() { | ||
| try { | ||
| const validatedInput = await this.inputAndValidation(); | ||
| return validatedInput; | ||
| } catch (error) { | ||
| OutputView.printError(error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| async repeatInput() { | ||
| for (let i = 0; i < 10; i++) { | ||
| const vlaidatedInput = await this.errorCatch(); | ||
| if (vlaidatedInput) return vlaidatedInput; | ||
| if (i === 5) throw new Error(ERROR_MESSAGES.enteredMoreFiveTimes); | ||
| } | ||
| } | ||
|
Comment on lines
+43
to
+49
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. repeatInput()이 반복되는 것 같은데 클래스의 상속이나 함수 등으로 모듈화 시켜도 좋을 것 같아요! 👍 |
||
| } | ||
|
|
||
| export default InputPurchaseModule; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { ERROR_MESSAGES } from '../constants/errorMessages.js'; | ||
| import validation from '../validation/validation.js'; | ||
| import InputView from '../view/InputView.js'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class InputWinningModule { | ||
| constructor() { | ||
| this.validation = new validation(); | ||
| } | ||
| async inputWinningNumber() { | ||
| const validatedLottoNumber = await this.repeatInput(); | ||
| const changgeTypeArray = validatedLottoNumber.split(',').map((string) => Number(string)); | ||
| OutputView.printSpace(); | ||
| return changgeTypeArray; | ||
| } | ||
|
|
||
| async inputAndValidation() { | ||
| const input = await InputView.readWinningNumber(); | ||
| this.validateWinningNumber(input); | ||
| return input; | ||
| } | ||
|
|
||
| validateWinningNumber(value) { | ||
| this.validation.empty(value); | ||
| this.validation.startedComma(value); | ||
| this.validation.endedComma(value); | ||
| const regExpPattern = /^\d(,\s?\d)*/; | ||
| this.validation.regularExpression(value, regExpPattern); | ||
| this.validation.winningNumberSixDigit(value); | ||
| } | ||
|
|
||
| async errorCatch() { | ||
| try { | ||
| const validatedInput = await this.inputAndValidation(); | ||
| return validatedInput; | ||
| } catch (error) { | ||
| OutputView.printError(error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| async repeatInput() { | ||
| for (let i = 0; i < 10; i++) { | ||
| const vlaidatedInput = await this.errorCatch(); | ||
| if (vlaidatedInput) return vlaidatedInput; | ||
| if (i === 5) throw new Error(ERROR_MESSAGES.enteredMoreFiveTimes); | ||
| } | ||
|
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. 시도 횟수 제한을 걸 생각은 못했는데, 좋은 방식인 듯 합니다 !! |
||
| } | ||
| } | ||
|
|
||
| export default InputWinningModule; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { MissionUtils } from '@woowacourse/mission-utils'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class PrintRandomNumber { | ||
| printRandomNumber(purchasQuantity) { | ||
| OutputView.printPurchaseNumber(purchasQuantity); | ||
| let lottoNumberArrayss = []; | ||
| for (let i = 0; i < purchasQuantity; i++) { | ||
| const lottoNumber = MissionUtils.Random.pickUniqueNumbersInRange(1, 45, 6); | ||
| const ascendingOrder = lottoNumber.sort((a, b) => a - b); | ||
| OutputView.printLottoNumber(ascendingOrder); | ||
| lottoNumberArrayss = [...lottoNumberArrayss, ascendingOrder]; | ||
| } | ||
|
Comment on lines
+12
to
+13
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. lottoNumberArrayss 마지막 s를 한번 더 적으셔서 오타가 있는 것 같습니다!
Owner
Author
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. 네 오타가 있네요 ㅜㅜ |
||
| OutputView.printSpace(); | ||
| return lottoNumberArrayss; | ||
| } | ||
| } | ||
|
|
||
| export default PrintRandomNumber; | ||
|
Comment on lines
+1
to
+19
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. 해당 파일과 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. 저도 같은 이유로 궁금합니다! 🤔 |
||
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.
줄바꿈인가요? 그냥 띄어쓰기해도 줄바꿈이 되는 경우도 있고 저 같은 경우는 \n으로 사용하는데,
사용하시는 이유가 궁금합니다!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.
위 아래 간격을 더 띄어놓고 문서형태로 볼 때 가독성을 더 높이기 위해서 사용했던 HTML 코드입니다.
잘 사용되지 않는 것이며 개인적인 만족감에 사용하였던 것입니다 ㅎㅎ
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.
@boramson 그렇군요 :) 감사합니다!