-
Notifications
You must be signed in to change notification settings - Fork 8
[로또] 김하빈 미션 제출합니다 #5
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: main
Are you sure you want to change the base?
Changes from all commits
d117f9f
11681d7
012a2a9
057c863
377ba15
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,42 @@ | ||
| # java-lotto-precourse | ||
|
|
||
| ## 기능의 분리 | ||
|
|
||
| ### 1. 입력부 | ||
|
|
||
| - 로또 구입 금액 입력 → 구현 | ||
| - 당첨 번호 입력 → 구현 | ||
| - 보너스 번호 입력 → 구현 | ||
|
|
||
| ### 2. 연산부 | ||
|
|
||
| - 로또 구입 개수 연산 → 구현 | ||
| - 랜덤한 로또 발행 연산 → 구현 | ||
| - 발행 로또의 당첨 내역 연산 | ||
| - 수익률 연산 | ||
|
|
||
| ### 3. 출력부 | ||
|
|
||
| - 로또 구입 개수 출력 **→ 문제 발생** | ||
| - 발행 로또 출력 | ||
| - 당첨 내역 출력 | ||
| - 수익률 출력 | ||
|
|
||
| ### 4. 예외부 | ||
|
|
||
| - 로또 구입 금액의 오류 | ||
|
|
||
| - 숫자 이외의 입력 → 구현 | ||
| - 1000원으로 나누어 떨어지지 않는 입력 → 구현 | ||
|
|
||
| - 당첨 번호의 오류 | ||
|
|
||
| - 숫자 이외의 입력 → 구현 | ||
| - 잘못된 구분기호의 입력 → 구현 | ||
| - 6개의 숫자가 아닌 입력 → 구현 | ||
| - 가능 숫자 범위를 벗어난 입력 → 구현 | ||
|
|
||
| - 보너스 번호의 오류 | ||
|
|
||
| - 숫자 이외의 입력 → 구현 | ||
| - 가능 숫자 범위를 벗어난 입력 → 구현 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| package lotto; | ||
|
|
||
| import lotto.view.InputMoney; | ||
| import lotto.view.OutputView; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| InputMoney money = new InputMoney(); | ||
| OutputView output = new OutputView(); | ||
|
|
||
| money.getMoney(); | ||
| output.showLottoCount(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package lotto.model; | ||
|
|
||
| import lotto.view.InputMoney; | ||
|
|
||
| public class LottoCount { | ||
|
|
||
| // 로또 구입 개수 연산 | ||
| public int setPurchaseLotto() { | ||
| InputMoney tmpMoney = new InputMoney(); | ||
|
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. 여기서 오류가 나는것 같아요!! 메인 어플리케이션에서 inputMoney를 하나 생성하셨는데 여기서 또 생성하면 입력이 두번 호출되니까용 여기서 new 를 통해 새 instance를 생성하는것보단 함수 파라미터로 기존 생성한 inputMoney를 받아서 사용하시고 inputMoney내부나 다른 코드로 한번 얻은 money값을 저장하는 변수를 두셔야할것 같아용 그 변수값만 불러오는 방식으로 바꾸시면 해결될 것 같아요! |
||
|
|
||
| int money = tmpMoney.getMoney(); | ||
| int lotto = money % 1000; | ||
|
|
||
| return lotto; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package lotto.view; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
|
|
||
| public class InputBonus { | ||
|
|
||
| // 보너스 번호 입력 | ||
| public int getBonus() { | ||
| while(true) { | ||
| try { | ||
| System.out.println("Please enter a bonus numbers."); | ||
| String strBonus = Console.readLine(); | ||
| int bonus = checkBonus(strBonus); | ||
| return bonus; | ||
| } | ||
|
|
||
| catch (NumberFormatException e) { | ||
| System.out.println("[ERROR] It is not a number."); | ||
| } | ||
|
|
||
| // 숫자 범위를 벗어나는 입력 | ||
| catch (IllegalArgumentException e) { | ||
| System.out.println("[ERROR] It is out of range."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 올바른 입력 체크 합수 | ||
| public int checkBonus(String strBonus) { | ||
|
|
||
|
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. view마다 check~~() 함수를 두는것보다 util 디렉토리 아래에 Validator 파일을 하나 만들어서 전체 코드에서 여러 검증만을 담당하게 코드를 짜도 좋을 것 같아요! |
||
| // 숫자인지 체크 | ||
| int bonus = Integer.parseInt(strBonus); | ||
|
|
||
| // 숫자 범위 확인 | ||
| if(bonus < 1 || bonus > 45) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| return bonus; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package lotto.view; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
| import java.lang.String; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class InputLotto { | ||
|
|
||
| // 당첨 번호 입력 | ||
| public List<Integer> getLotto() { | ||
| while(true) { // 예외 발생 시 반복적인 입력을 받기 위한 반복문 | ||
| try { | ||
| System.out.println("Please enter a lotto numbers."); | ||
| String strLotto = Console.readLine(); | ||
| List<Integer> lotto = checkLotto(strLotto); | ||
| return lotto; | ||
| } | ||
|
|
||
| // 숫자가 아니거나 구분자가 이상한 입력 | ||
| catch (NumberFormatException e) { | ||
| System.out.println("[ERROR] It is not a valid lotto."); | ||
| } | ||
|
|
||
| // 숫자 범위를 벗어나는 입력 | ||
| catch (IllegalArgumentException e) { | ||
| System.out.println("[ERROR] It is out of range."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 올바른 입력 체크 함수 | ||
| public List<Integer> checkLotto(String lotto) { | ||
| List<Integer> arrLotto = new ArrayList<Integer>(); | ||
|
|
||
| // 구분자(,)를 기준으로 문자열 자르기 | ||
| String[] strLotto = lotto.split(","); | ||
|
|
||
| // 문자를 숫자로 변환 | ||
| for (int i = 0; i < strLotto.length; i++) { | ||
| arrLotto.add(Integer.parseInt(strLotto[i])); | ||
| } | ||
|
|
||
| // 숫자 개수 확인 | ||
| if (arrLotto.size() != 6) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| // 숫자 범위 확인 | ||
| for (int i = 0; i < arrLotto.size(); i++) { | ||
| if(arrLotto.get(i) < 1 || arrLotto.get(i) > 45) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| return arrLotto; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package lotto.view; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
|
|
||
| public class InputMoney { | ||
|
|
||
| // 로또 구입 금액 입력 | ||
| public int getMoney() { | ||
| while(true) { // 예외 발생 시 반복적인 입력을 받기 위한 반복문 | ||
| try { | ||
| System.out.println("Please enter a money."); | ||
| int money = Integer.parseInt(Console.readLine()); | ||
| checkMoney(money); | ||
| return money; | ||
| } | ||
|
|
||
| // 숫자 이외의 입력 | ||
| catch (NumberFormatException e) { | ||
| System.out.println("[ERROR] It is not a number."); | ||
| } | ||
|
|
||
| // 1000원으로 나누어 떨어지지 않는 입력 | ||
| catch (IllegalArgumentException e) { | ||
| System.out.println("[ERROR] It is not a valid money."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 1000원으로 나누어 떨어지지 않는 입력 체크 함수 | ||
| public void checkMoney(int money) { | ||
| int value = money % 1000; | ||
| if(value != 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package lotto.view; | ||
|
|
||
| import lotto.model.LottoCount; | ||
|
|
||
| public class OutputView { | ||
| public void showLottoCount() { | ||
| LottoCount lottoCount = new LottoCount(); | ||
| System.out.println(lottoCount.setPurchaseLotto() + " purchase lotto."); | ||
| } | ||
| } |
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.
view들만 사용하는것보단 view와 모델 사이의 상호작용을 관리할 controller를 만드시는게 더 좋을것 같습니다~~