-
Notifications
You must be signed in to change notification settings - Fork 52
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
[로또 미션] 오지현 미션 제출합니다. #20
base: zhy2on
Are you sure you want to change the base?
Changes from 1 commit
a4853f5
d1c287a
fda63c4
a39799b
9864dfd
26ddc72
5b04e8e
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import controller.LottoController; | ||
|
||
public class LottoApplication { | ||
|
||
public static void main(String[] args) { | ||
LottoController controller = new LottoController(); | ||
controller.run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package controller; | ||
|
||
import domain.LottoTicket; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class LottoController { | ||
public void run() { | ||
int amountToBuy = InputView.getAmountToBuy(); | ||
List<LottoTicket> tickets = buyLottoTickets(amountToBuy); | ||
OutputView.displayTicketCount(tickets.size()); | ||
OutputView.displayLottoTickets(tickets); | ||
} | ||
|
||
private List<LottoTicket> buyLottoTickets(final int amountToBuy) { | ||
int ticketCount = amountToBuy / LottoTicket.getLottoPrice(); | ||
return generateLottoTickets(ticketCount); | ||
} | ||
|
||
private List<LottoTicket> generateLottoTickets(final int ticketCount) { | ||
return IntStream.range(0, ticketCount) | ||
.mapToObj(i -> new LottoTicket()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
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,36 @@ | ||
package domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class LottoTicket { | ||
private static final int LOTTO_PRICE = 1000; | ||
private static final int LOTTO_NUMBER_COUNT = 6; | ||
private static final int LOTTO_NUMBER_MAX = 45; | ||
|
||
private List<Integer> numbers; | ||
|
||
public LottoTicket() { | ||
this.numbers = generateLottoNumbers(); | ||
} | ||
|
||
private List<Integer> generateLottoNumbers() { | ||
List<Integer> numbers = new ArrayList<>(); | ||
for (int i = 1; i <= LOTTO_NUMBER_MAX; i++) { | ||
numbers.add(i); | ||
} | ||
Collections.shuffle(numbers); | ||
List<Integer> selectedNumbers = numbers.subList(0, LOTTO_NUMBER_COUNT); | ||
Collections.sort(selectedNumbers); // 오름차순 정렬 | ||
return selectedNumbers; | ||
} | ||
|
||
public List<Integer> getNumbers() { | ||
return numbers; | ||
} | ||
|
||
public static int getLottoPrice() { | ||
return LOTTO_PRICE; | ||
} | ||
} |
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,12 @@ | ||
package view; | ||
|
||
import java.util.Scanner; | ||
|
||
public class InputView { | ||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
public static int getAmountToBuy() { | ||
System.out.println("구입금액을 입력해 주세요."); | ||
return scanner.nextInt(); | ||
} | ||
} |
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,17 @@ | ||
package view; | ||
|
||
import domain.LottoTicket; | ||
|
||
import java.util.List; | ||
|
||
public class OutputView { | ||
public static void displayTicketCount(final int ticketCount) { | ||
System.out.println(ticketCount + "개를 구매했습니다."); | ||
} | ||
|
||
public static void displayLottoTickets(final List<LottoTicket> tickets) { | ||
for (LottoTicket ticket : tickets) { | ||
System.out.println(ticket.getNumbers()); | ||
} | ||
} | ||
} |
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.
1단계에서 구현을 하신 것처럼 Controller 안에서 말고 Application 안에서 컨트롤러 객체 생성 후 controller.run() 사용하시면 좋을 것 같습니다.