-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Step2 - 로또(자동) #3786
base: sojournre
Are you sure you want to change the base?
Step2 - 로또(자동) #3786
Conversation
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.
과정이 끝났음에도 불구하고 미션 진행 👍
아직 객체 설계하는데 어려움이 느껴지는 것 같아요.
그런 만큼 로또 미션에서 객체 설계 연습에 집중해 보면 좋겠네요.
문자열, 원시값을 포장, 일급 콜렉션을 적용해 클래스 분리하는 연습 집중해 볼 것을 추천해요.
public static void main(String[] args) { | ||
// 사용자로부터 구매 금액 입력받기 | ||
String purchaseAmount = readInput("구입금액을 입력해 주세요."); | ||
int purchaseCount = calculateTicketCount(purchaseAmount); |
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.
원시 값을 포장하는 원칙을 시도해 보는 것은 어떨까?
printPurchaseTickets(purchaseCount); | ||
|
||
// 로또 자동 생성 및 출력 | ||
List<List<Integer>> tickets = generateTickets(purchaseCount); |
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.
2중으로 콜렉션을 쓰기보다 가능하면 객체로 포장해 하나의 콜렉션을 사용할 것을 추천
List를 객체로 포장하는 것은 어떨까?
public static final int LOTTO_PRICE = 1000; | ||
private static final int LOTTO_COUNT = 6; | ||
private static final int LOTTO_MAX = 45; | ||
|
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.
클래스 메서드로 구현하지 않고 List을 인스턴스 변수로 가지는 객체로 구현하는 것은 어떨까?
List<Integer> numbers = new ArrayList<>(); | ||
|
||
for (int i = 1; i <= LOTTO_MAX; i++) { | ||
numbers.add(i); | ||
} |
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.
이와 같이 구현할 경우 로또를 생성할 때마다 45개의 값을 콜렉션에 담아야 한다.
그 보다 45개의 값을 가지는 콜렉션을 재사용하는 방식으로 구현하는 것은 어떨까?
return result; | ||
} | ||
|
||
public static List<Integer> parse(String input) { |
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.
이 메서드는 두 가지 이상의 일을 하고 있다.
메서드가 한 가지 일만 하도록 리팩터링해 보면 어떨까?
import static lotto.domain.Lotto.LOTTO_PRICE; | ||
import static lotto.domain.Lotto.matchCount; | ||
|
||
public enum LottoPrize { |
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.
enum 사용 👍
List<Integer> winningNumbers = List.of(1, 2, 3, 4, 5, 6); | ||
List<List<Integer>> purchasedTickets = Arrays.asList( | ||
List.of(8, 21, 23, 41, 42, 43), | ||
List.of(3, 5, 11, 16, 32, 38), | ||
List.of(7, 11, 16, 35, 36, 44), | ||
List.of(1, 8, 11, 31, 41, 42), | ||
List.of(13, 14, 16, 38, 42, 45), | ||
List.of(7, 11, 30, 40, 42, 43), | ||
List.of(2, 13, 22, 32, 38, 45), | ||
List.of(23, 25, 33, 36, 39, 41), | ||
List.of(1, 3, 5, 14, 22, 45), | ||
List.of(5, 9, 38, 41, 43, 44), | ||
List.of(2, 8, 9, 18, 19, 21), | ||
List.of(13, 14, 18, 21, 23, 35), | ||
List.of(17, 21, 29, 37, 42, 45), | ||
List.of(3, 8, 27, 30, 35, 44) | ||
); |
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.
테스트 fixture 구현부가 너무 크다.
로또 당첨 결과만을 가지는 객체를 만들고 이 객체가 수익률을 계산하도록 구현하는 것은 어떨까?
No description provided.