-
Notifications
You must be signed in to change notification settings - Fork 92
test #132
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: codereview-test
Are you sure you want to change the base?
test #132
Changes from all commits
958541e
8627586
c086150
d435b8e
07b7bc7
5ed6fea
2fd7c31
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,10 @@ | ||
import controller.LottoController; | ||
|
||
import java.io.IOException; | ||
|
||
public class Application { | ||
|
||
public static void main(String [] args) throws IOException { | ||
LottoController lottoController = new LottoController(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controller; | ||
|
||
import model.AutoLotto; | ||
import model.Lotto; | ||
import model.LottoList; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LottoController { | ||
Comment on lines
+10
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.
이런 경우, 의존성을 외부에서 주입하는 의존성 주입(Dependency Injection) 방식을 고려해보면 어떨까요? 예를 들어, |
||
private InputView inputView = new InputView(); | ||
private OutputView outputView = new OutputView(); | ||
private AutoLotto autoLotto; | ||
private LottoList lottoList; | ||
|
||
|
||
public LottoController(){ | ||
lottoStart(); | ||
} | ||
Comment on lines
+18
to
+21
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.
|
||
public void lottoStart() { | ||
int price = inputMoney(); | ||
viewLotto(price); | ||
} | ||
Comment on lines
+22
to
+25
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.
|
||
|
||
public int inputMoney(){ | ||
Comment on lines
+24
to
+27
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.
|
||
return inputView.inputPrice(); | ||
} | ||
Comment on lines
+26
to
+29
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.
|
||
public void viewLotto(int price){ | ||
int count = price/1000; | ||
outputView.countPrint(count); | ||
lottoList = makeLottolist(count); | ||
} | ||
public LottoList makeLottolist(int count){ | ||
Comment on lines
+31
to
+35
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.
|
||
for(int i=0; i<count; i++){ | ||
lottoList = new LottoList(makeLotto()); | ||
} | ||
return lottoList; | ||
} | ||
public Lotto makeLotto(){ | ||
List<Integer> lotto = new ArrayList<>(); | ||
AutoLotto autoLotto = new AutoLotto(); | ||
lotto = autoLotto.getAutoLotto(); | ||
outputView.lottoPrint(lotto); | ||
return new Lotto(lotto); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package model; | ||
|
||
import java.util.*; | ||
|
||
public class AutoLotto { | ||
|
||
private static final int MAX_LOTTO_NUMBER = 45; | ||
private static final int CNT_LOTTO_NUMBER = 6; | ||
|
||
private static List<Integer> lottoNums = new ArrayList<>(); | ||
public AutoLotto(){ | ||
createAutoLotto(); | ||
Comment on lines
+10
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.
로또 번호는 각 로또 객체마다 독립적인 값을 가져야 하므로, |
||
} | ||
public void createAutoLotto(){ | ||
Random random = new Random(); | ||
Set<Integer> uniqueNumbers = new TreeSet<>(); // 중복되지 않는 숫자를 보장하는 TreeSet 사용 | ||
|
||
// 로또 번호 생성 | ||
while (uniqueNumbers.size() < CNT_LOTTO_NUMBER) { | ||
int num = random.nextInt(MAX_LOTTO_NUMBER) + 1; | ||
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.
|
||
uniqueNumbers.add(num); | ||
} | ||
|
||
lottoNums = new ArrayList<>(uniqueNumbers); | ||
|
||
} | ||
public List<Integer> sortLotto(List<Integer> lottoNums){ | ||
Comment on lines
+20
to
+27
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.
만약 로또 번호를 항상 정렬된 상태로 사용해야 한다면,
Comment on lines
+23
to
+27
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.
|
||
List<Integer> sortLottoList = new ArrayList<>(lottoNums); | ||
sortLottoList.sort(Comparator.naturalOrder()); | ||
return sortLottoList; | ||
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.
|
||
} | ||
public List<Integer> getAutoLotto(){ | ||
return lottoNums; | ||
Comment on lines
+29
to
+33
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,16 @@ | ||
package model; | ||
|
||
import java.util.List; | ||
|
||
public class Lotto { | ||
private static final int BONUS_NUMBER_INDEX = 6; | ||
private final List<Integer> numbers; | ||
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.
|
||
|
||
public Lotto(List<Integer> numbers) { | ||
this.numbers = numbers; | ||
Comment on lines
+7
to
+10
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.
각 로또는 자신만의 번호 리스트를 가져야 하므로, |
||
} | ||
|
||
public List<Integer>getNumbers(){ | ||
return numbers; | ||
} | ||
Comment on lines
+13
to
+15
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,22 @@ | ||
package model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
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.
|
||
public class LottoList { | ||
List<Lotto> lottoList = new ArrayList<>(); | ||
private int totalPrice; | ||
|
||
public LottoList(Lotto lotto){ | ||
Comment on lines
+7
to
+10
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.
|
||
lottoList.add(lotto); | ||
} | ||
public List<Lotto> getLottoList(){ | ||
return lottoList; | ||
} | ||
Comment on lines
+14
to
+15
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.
|
||
public void setTotalPrice(int reward){ | ||
this.totalPrice+=reward; | ||
} | ||
public int getTotalPrice(){ | ||
return totalPrice; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package view; | ||
|
||
import java.util.Scanner; | ||
|
||
public class InputView { | ||
|
||
private final static String INPUT_PRICE = "구입금액을 입력해 주세요."; | ||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
|
||
public int inputPrice(){ | ||
System.out.println(INPUT_PRICE); | ||
int price = scanner.nextInt(); | ||
return price; | ||
Comment on lines
+11
to
+14
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.
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package view; | ||
|
||
import java.util.List; | ||
|
||
public class OutputView { | ||
|
||
private final static String BUY_MESSAGE = "개를 구매했습니다."; | ||
|
||
public void countPrint (int count){ | ||
System.out.println("\n" + count + BUY_MESSAGE); | ||
|
||
} | ||
public void lottoPrint(List<Integer> numbers) { | ||
Comment on lines
+11
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.
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.
|
||
System.out.println(numbers); | ||
} | ||
Comment on lines
+14
to
+15
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.
Pending 리뷰 테스트 코멘트