Skip to content
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

로또 미션 제출합니다 :) #62

Open
wants to merge 6 commits into
base: jermany17
Choose a base branch
from

Conversation

jermany17
Copy link

domain = 핵심 비즈니스 로직을 가지는 객체 - Lotto.java, LottoGame.java
view = UI 관련한 객체(입출력) - Input.java, Output.java
controller = 최종 애플리케이션 구현 - App.java
test = domain의 단위 테스트 구현 - LottoTest.java

<App 실행 결과>
구입금액을 입력해 주세요.
14000

수동으로 구매할 로또 수를 입력해 주세요.
5

수동으로 구매할 번호를 입력해 주세요.
6, 5, 4, 3, 2, 1
7, 5, 4, 3, 2, 1
8, 5, 4, 3, 2, 1
9, 8, 4, 3, 2, 1
10, 9, 8, 3, 2, 1

수동으로 5장, 자동으로 9개를 구매했습니다.
[11, 22, 26, 36, 40, 5]
[12, 13, 16, 25, 28, 9]
[10, 23, 35, 37, 38, 44]
[10, 2, 26, 36, 43, 45]
[17, 2, 30, 31, 32, 7]
[20, 22, 23, 29, 36, 44]
[17, 2, 35, 41, 6, 9]
[12, 19, 22, 37, 41, 45]
[16, 33, 34, 42, 43, 8]

지난 주 당첨 번호를 입력해 주세요.
1, 2, 3, 4, 5, 6

보너스 볼을 입력해 주세요.
7

당첨 통계

3개 일치 (5000원)- 1개
4개 일치 (50000원)- 1개
5개 일치 (1500000원)- 1개
5개 일치, 보너스 볼 일치(30000000)원 - 1개
6개 일치 (2000000000원)-1개
총 수익률은 145111.07입니다.

Copy link

@be-student be-student left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨어요!
전체적으로 잘 짜주셨어요
값 객체나, 테스트를 조금 더 추가해봐도 좋을 것 같아요!
특히 돈 계산하는 부분에 테스트가 있으면 좋을 것 같아요

}

// 수동과 자동 구매 개수를 출력한다
Output.ManualAndAutoNumOutput(manual, auto);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 컨벤션상 메소드는 소문자로 해주시면 좋을 것 같아요!

import view.Output;

public class App {
public static void main(String[] args) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 메인 함수가 전체적으로 긴 느낌이 드는데요 이 부분을 적절한 기준에 따라서 함수를 쪼개보면 어떨까요?

Comment on lines +32 to +37
for (int i = 0; i < auto; i++) {
List<String> autoLotto = Input.AutoLottoInput();
Collections.sort(autoLotto);
LottoList.add(autoLotto);
Output.LottoNumOutput(autoLotto);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 정렬까지 컨트롤러가 하게 되면 약간 컨트롤러의 책임이 많아지는 것 같은데 어떻게 생각하시나요?
컨트롤러의 책임이 많아진다는 것은 결국 수많은 코드들이 다 컨트롤러로 오고, 아무도 건드릴 수 없는 거대한 코드 덩어리가 된다는 의미이기도 합니다

Output.LottoNumOutput(autoLotto);
}

// 지난 주 당첨 번호를 입력한다

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석 달아주시는 습관 아주 좋습니다

Comment on lines +8 to +14
int matchNum = 0;
for (String n : Lotto) {
if (LastWeekLotto.contains(n)) {
matchNum++;
}
}
return matchNum;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent 1규칙을 지키려고 시도해보셔도 좋을 것 같아요!

System.out.println("구입금액을 입력해 주세요.");
int money = scanner.nextInt();
System.out.println();
return money/1000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 부분은 비즈니스 로직이 아닐까요? money /1000 부분이요!
view 와 비즈니스 로직은 최대한 분리해보셔도 좋을 것 같아요

public static List<String> AutoLottoInput() {
List<String> lottoRange = new ArrayList<>();
for (int i = 1; i <= 45; i++) {
lottoRange.add(String.valueOf(i));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로또 숫자가 String 이 된 이유가 있을까요? 로또 숫자는 숫자다보니 정수 타입이 적절할 것 같아서요
만약 추가적인 비즈니스 룰이 있다면 값객체로 만들어봐도 좋을 것 같아요
https://velog.io/@cjh8746/%EC%97%94%ED%8B%B0%ED%8B%B0entity%EC%99%80-%EA%B0%92%EA%B0%9D%EC%B2%B4value-object%EC%97%90-%EB%8C%80%ED%95%B4%EC%84%9C

Comment on lines +57 to +59
public static void closeScanner() {
if (scanner != null) {
scanner.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 쓰라는 것은 아니지만, Autocloseable 도 한번 보시면 좋을 것 같아요!
만약 적용한다면 어떻게 될지도 봐도 재밌겠네요

Comment on lines +24 to +53
public static void ResultOfLotto(List<List<String>> LottoList, List<String> LastWeekLotto, String BonusBall, int moneyInput){
int result3 = 0, result4 = 0, result5 = 0, result6 = 0, result5Bonus = 0;
int matchNum = 0, matchBonus = 0;
int resultMoney = 0;
double rate = 0;

for (List<String> Lotto : LottoList) {
matchNum = LottoGame.matchNum(Lotto, LastWeekLotto);
matchBonus = LottoGame.matchBonus(Lotto, BonusBall);
if (matchNum == 3) {
result3++;
resultMoney += 5000;
}
if (matchNum == 4) {
result4++;
resultMoney += 50000;
}
if (matchNum == 5 && matchBonus == 0) {
result5++;
resultMoney += 1500000;
}
if (matchNum == 5 && matchBonus == 1) {
result5Bonus++;
resultMoney += 30000000;
}
if (matchNum == 6) {
result6++;
resultMoney += 2000000000;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 부분은 비즈니스가 아닐까요?

Comment on lines +10 to +54
@Test
@DisplayName("로또번호_6개_일치여부를_확인한다")
public void 로또번호_6개_일치여부를_확인한다() {
List<String> lotto = Arrays.asList("1", "2", "3", "4", "5", "6");
List<String> lastWeekLotto = Arrays.asList("6", "5", "4", "3", "2", "1");
int result = LottoGame.matchNum(lotto, lastWeekLotto);
assertEquals(6, result);
}

@Test
@DisplayName("로또번호_3개_일치여부를_확인한다")
public void 로또번호_3개_일치여부를_확인한다() {
List<String> lotto = Arrays.asList("1", "2", "3", "4", "5", "6");
List<String> lastWeekLotto = Arrays.asList("10", "9", "8", "3", "2", "1");
int result = LottoGame.matchNum(lotto, lastWeekLotto);
assertEquals(3, result);
}

@Test
@DisplayName("로또번호_0개_일치여부를_확인한다")
public void 로또번호_0개_일치여부를_확인한다() {
List<String> lotto = Arrays.asList("1", "2", "3", "4", "5", "6");
List<String> lastWeekLotto = Arrays.asList("7", "8", "9", "10", "11", "12");
int result = LottoGame.matchNum(lotto, lastWeekLotto);
assertEquals(0, result);
}

@Test
@DisplayName("보너스번호_일치여부를_확인한다")
public void 보너스번호_일치여부를_확인한다() {
List<String> lotto = Arrays.asList("1", "2", "3", "4", "5", "7");
String bonusBall = "7";
int result = LottoGame.matchBonus(lotto, bonusBall);
assertEquals(1, result); // 보너스볼이 일치함
}

@Test
@DisplayName("보너스번호_불일치여부를_확인한다")
public void 보너스번호_불일치여부를_확인한다() {
List<String> lotto = Arrays.asList("1", "2", "3", "4", "5", "7");
String bonusBall = "8";
int result = LottoGame.matchBonus(lotto, bonusBall);
assertEquals(0, result); // 보너스볼이 일치하지 않음
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 너무 잘 해주셨어요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants