-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3ba83a
commit 562d80f
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Lotto { | ||
private List<Integer> numbers; | ||
|
||
public Lotto(List<Integer> numbers) { | ||
Collections.sort(numbers); | ||
this.numbers = numbers; | ||
} | ||
|
||
public List<Integer> getNumbers() { | ||
return numbers; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return numbers.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import java.util.List; | ||
|
||
public class LottoApp { | ||
public static void main(String[] args) { | ||
LottoMachine lottoMachine = new LottoMachine(); | ||
int purchaseAmount = lottoMachine.getPurchaseAmount(); | ||
int numberOfLottos = lottoMachine.calculateNumberOfLottos(purchaseAmount); | ||
lottoMachine.printPurchaseInfo(numberOfLottos); | ||
List<Lotto> lottos = lottoMachine.generateLottos(numberOfLottos); | ||
lottoMachine.printLottos(lottos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class LottoMachine { | ||
private static final int LOTTO_PRICE = 1000; | ||
private static final int LOTTO_NUMBER_COUNT = 6; | ||
private static final int LOTTO_MAX_NUMBER = 45; | ||
|
||
public int getPurchaseAmount() { | ||
Scanner scanner = new Scanner(System.in); | ||
System.out.println("구입금액을 입력해 주세요."); | ||
return scanner.nextInt(); | ||
} | ||
|
||
public int calculateNumberOfLottos(int purchaseAmount) { | ||
return purchaseAmount / LOTTO_PRICE; | ||
} | ||
|
||
public void printPurchaseInfo(int numberOfLottos) { | ||
System.out.println(numberOfLottos + "개를 구매했습니다."); | ||
} | ||
|
||
public List<Lotto> generateLottos(int numberOfLottos) { | ||
List<Lotto> lottos = new ArrayList<>(); | ||
for (int i = 0; i < numberOfLottos; i++) { | ||
lottos.add(generateLotto()); | ||
} | ||
return lottos; | ||
} | ||
|
||
private Lotto generateLotto() { | ||
List<Integer> numbers = new ArrayList<>(); | ||
for (int i = 1; i <= LOTTO_MAX_NUMBER; i++) { | ||
numbers.add(i); | ||
} | ||
Collections.shuffle(numbers); | ||
return new Lotto(numbers.subList(0, LOTTO_NUMBER_COUNT)); | ||
} | ||
|
||
public void printLottos(List<Lotto> lottos) { | ||
for (Lotto lotto : lottos) { | ||
System.out.println(lotto); | ||
} | ||
} | ||
} |