Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ repositories {
}

dependencies {
implementation 'com.github.woowacourse-projects:mission-utils:1.0.0'


implementation 'com.github.kokodak:mission-utils:1.0.0'

implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
implementation 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'org.mockito:mockito-inline:3.12.4'
implementation 'org.assertj:assertj-core:3.21.0'
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'

}

java {
Expand All @@ -23,6 +27,8 @@ java {
}
}


test {
useJUnitPlatform()
}

83 changes: 83 additions & 0 deletions src/main/java/lotto/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,90 @@
package lotto;

import lotto.controller.LottoController;

import java.util.Scanner;

Choose a reason for hiding this comment

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

혹시.. 스캐너 사용 하셨나요?

Copy link
Author

Choose a reason for hiding this comment

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

처음에 모르고 사용했다가 지우는 과정에서 깜빡했네요!


public class Application {

public static void main(String[] args) {
LottoController lottoController = new LottoController();
lottoController.run();


// TODO: 프로그램 구현

}
}









//
//package lotto;
//
//import org.kokodak.Randoms;
//import org.kokodak.Console;
//
//
//
//public class Application {
// public static void main(String[] args) {
// // TODO: 프로그램 구현
//
// int[] lotto = new int[6];
// Randoms randoms = new Randoms;
//
// Lotto(randoms.in);
//
// int money;
// int bonus_number;
//
//
//
//
// System.out.print("구입 금액을 입력하세요: ");
//
// System.out.println("당첨 번호를 입력하세요(쉼표로 구분): ");
//
// System.out.println("보너스 번호를 입력하세요: ");
//
//
//
//
//
//
//
//
// for (int i = 0; i < lotto.length; i++) {
// lotto[i] = random.nextInt(45) + 1;
// // 중복번호 제거
// for(int j = 0; j < i; j++) {
// if(lotto[i] == lotto[j]) {
// i--;
// break;
// }
// }
// }
//
// // 오름차순 정렬
// for(int i = 0; i < lotto.length; i++) {
// for(int j = i + 1; j < lotto.length; j++) {
// if(lotto[i] > lotto[j]) {
// int temp = lotto[i];
// lotto[i] = lotto[j];
// lotto[j] = temp;
// }
// }
// }
//
// // 랜덤번호 출력
// System.out.println("* 로또번호 : " + Arrays.toString(lotto));
//
//
// }
//}
40 changes: 20 additions & 20 deletions src/main/java/lotto/Lotto.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package lotto;

import java.util.List;

public class Lotto {
private final List<Integer> numbers;

public Lotto(List<Integer> numbers) {
validate(numbers);
this.numbers = numbers;
}

private void validate(List<Integer> numbers) {
if (numbers.size() != 6) {
throw new IllegalArgumentException();
}
}

// TODO: 추가 기능 구현
}
//package lotto;
//
//import java.util.List;
//
//public class Lotto {
// private final List<Integer> numbers;
//
// public Lotto(List<Integer> numbers) {
// validate(numbers);
// this.numbers = numbers;
// }
//
// private void validate(List<Integer> numbers) {
// if (numbers.size() != 6) {
// throw new IllegalArgumentException();
// }
// }
//
// // TODO: 추가 기능 구현
//}
59 changes: 59 additions & 0 deletions src/main/java/lotto/domain/Lotto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package lotto.domain;

import lotto.view.ExceptionMessage;

import java.util.*;

public class Lotto {
private static final int minNumber = 1;
private static final int maxNumber = 45;
private final List<Integer> numbers;
public Lotto(List<Integer> numbers){
validate(numbers);
validateOverlap(numbers);
validateRange(numbers);

Collections.sort(numbers);
this.numbers = numbers;
}
public List<Integer> getLottoNumbers(){
return numbers;
}
public int countMatch(Lotto winLotto){
return (int) numbers.stream().filter(winLotto::containNumber).count();
}
public boolean containNumber(int number){
return numbers.contains(number);
}
private void validate(List<Integer> numbers){
if(numbers.size() != 6){
ExceptionMessage.sizeException();
throw new IllegalArgumentException();
}
}
private void validateOverlap(List<Integer> numbers){
Set<Integer> overlapCheck = new HashSet<>();
for (int i = 0; i< numbers.size();i++){
overlapCheck.add(numbers.get(i));
}
if (overlapCheck.size() != 6){
ExceptionMessage.overlapException();
throw new IllegalArgumentException();
}
}
private void validateRange(List<Integer> numbers){
for (int winNumber = 0;winNumber<numbers.size();winNumber++){
if (numbers.get(winNumber) < minNumber || numbers.get(winNumber) > maxNumber){
ExceptionMessage.rangeException();
throw new IllegalArgumentException();
}
}
}
public static void validateBonusNumber(List<Integer> numbers, int bonusNumber){
if (numbers.contains(bonusNumber)){
ExceptionMessage.overlapException();
throw new IllegalArgumentException();
}
}

}
22 changes: 22 additions & 0 deletions src/main/java/lotto/domain/LottoNumbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lotto.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import camp.nextstep.edu.missionutils.Randoms;

public class LottoNumbers {
public LottoNumbers(){

}
private static final int cntLottoNumber = 6;
private static final int minLottoNumber = 1;
private static final int maxLottoNumber = 45;
private static List<Integer> lottoNumberList;
public static List<Integer> setRandomNumbers(){
lottoNumberList = Randoms.pickUniqueNumbersInRange(minLottoNumber,maxLottoNumber,cntLottoNumber);
List<Integer> lottoTicketNumberList = new ArrayList<>(lottoNumberList);
Collections.sort(lottoTicketNumberList);
return lottoTicketNumberList;
}
}
39 changes: 39 additions & 0 deletions src/main/java/lotto/domain/PlayerLottoAmount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package lotto.domain;
import lotto.view.ExceptionMessage;

public class PlayerLottoAmount {
private static final int lottoPrice = 1000;
private final int coin;
public PlayerLottoAmount(String coin){
int coinNum = validateNumber(coin);
validateCoin(coinNum);
this.coin = coinNum;
}
public int calcLottoCount(){
return coin / lottoPrice;
}
private void validateCoin(int coin){
validateNatural(coin);
validateDivisible(coin);
}
private static int validateNumber(String coin) throws IllegalArgumentException{
try{
return Integer.parseInt(coin);
} catch (NumberFormatException e){
ExceptionMessage.numberException();
throw new IllegalArgumentException();
}
}
private void validateNatural(int coin){
if (coin <= 0) {
ExceptionMessage.naturalException();
throw new IllegalArgumentException();
}
}
private void validateDivisible(int coin){
if (coin % lottoPrice != 0){
ExceptionMessage.divisibleException();
throw new IllegalArgumentException();
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/lotto/domain/Ranking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package lotto.domain;

import lotto.view.OutputView;

public enum Ranking {
first(6,2_000_000_000, "6개 일치 (2,000,000,000원) - "),
second(5,30_000_000, "5개 일치, 보너스 볼 일치 (30,000,000원) - "),
third(5,1_500_000, "5개 일치 (1,500,000원) - "),

fourth(4,50_000, "4개 일치 (50,000원) - "),
fifth(3,5_000, "3개 일치 (5,000원) - "),
miss(0,0,"");

public int getMatchCount() {
return matchCount;
}

public int getWinAmount() {
return winAmount;
}
private boolean counter(int matchCount){
return this.matchCount == matchCount;
}
public void printMessage(int cnt){
if (this!=miss){
OutputView.printSuccessMessage(message,cnt);
}
}


Ranking(int matchCount, int winAmount, String message){
this.matchCount = matchCount;
this.winAmount = winAmount;
this.message = message;
}
private static final int winMinCount = 3;
private static final String errorMessage = "[ERROR]";

private int matchCount;
private int winAmount;
private String message;
public static Ranking valueOf(int matchCount,boolean matchBonus){
if (matchCount < winMinCount){
return miss;
}
if (second.counter(matchCount) && matchBonus){
return second;
}
for (Ranking rank : values()){
if (rank.counter(matchCount)&&rank != second){
return rank;
}
}
throw new IllegalArgumentException(errorMessage);
}

}
15 changes: 15 additions & 0 deletions src/main/java/lotto/domain/WinResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lotto.domain;

public class WinResult {
private final Lotto lotto;
private final int bonus;
public WinResult(Lotto lotto,int bonus){
this.lotto = lotto;
this.bonus = bonus;
}
public Ranking match(Lotto playername){
int matchCount = playername.countMatch(lotto);
boolean bonusCheck = playername.containNumber(bonus);
return Ranking.valueOf(matchCount,bonusCheck);
}
}
Loading