-
Notifications
You must be signed in to change notification settings - Fork 39
[스프링 화요일 2팀](권세욱) 미션 제출합니다 #22
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: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| package lotto; | ||
|
|
||
| import lotto.Controller.Start; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| Start start = new Start(); | ||
| start.run(); | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package lotto.Controller; | ||
|
|
||
| import lotto.View.InOut; | ||
| import lotto.Domain.Lotto; | ||
| import lotto.Domain.LottoResult; | ||
| import lotto.Domain.RandomLotto; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class Start { | ||
| public Start(){} | ||
|
|
||
| public int FIRST = 0; //6개 - 2,000,000,000 | ||
| public int SECOND = 0; //5개 + 보너스 - 50,000,000 | ||
| public int THIRD = 0; //5개 - 1,500,000 | ||
| public int FORTH = 0; //4개 - 50,000 | ||
| public int FIVTH = 0; //3개 - 5,000 | ||
|
|
||
|
|
||
| public void run(){ | ||
| InOut inOut = new InOut(); | ||
| LottoResult lottoResult = new LottoResult(); | ||
| RandomLotto randomLotto = new RandomLotto(); | ||
|
|
||
| int LottoAmount =inOut.InLottoMoney()/1000; //로또 개수 확인 | ||
|
|
||
| List<List> myRandomLottoList = randomLotto.setRandomLottoList(LottoAmount); //LottoAmount 개의 랜덤 로또 번호 생성 | ||
|
|
||
|
|
||
| inOut.OutLottoAmount(LottoAmount); //로또 개수 출력 | ||
| inOut.OutLottoList(myRandomLottoList); //랜덤으로 생성된 로또 출력 | ||
|
|
||
| List<Integer> WinningLotto = inOut.InWinningLotto(); //로또 당첨 번호 입력 | ||
| int BonusNum = inOut.InBonusNum(); //보너스 번호 입력 | ||
|
|
||
| for(List<Integer> LottoList : myRandomLottoList){ //로또 당첨 결과 설정 | ||
| int Count = lottoResult.getResult(LottoList,WinningLotto); | ||
| setResult(Count,WinningLotto,BonusNum); } | ||
|
|
||
| double RateOfReturn = lottoResult.getRateOfReturn(getResultMoney(),LottoAmount*1000); //수익률 | ||
|
|
||
| inOut.OutResultStatistics(FIRST,SECOND,THIRD,FORTH,FIVTH,RateOfReturn); //결과 출력 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| private void setResult(Integer Count,List<Integer> WinningLotto , Integer BonusNum){ //등수에 해당하는 로또 개수 업데이트 | ||
| LottoResult lottoResult = new LottoResult(); | ||
| switch (Count){ | ||
| case 3: | ||
| FIVTH++; | ||
| break; | ||
| case 4: | ||
| FORTH++; | ||
| break; | ||
| case 5: | ||
| if(lottoResult.getBounsResult(BonusNum,WinningLotto) == Boolean.TRUE){ | ||
| //System.out.println("보너스 o"); | ||
| SECOND++; | ||
| break; | ||
| } | ||
| else if(lottoResult.getBounsResult(BonusNum,WinningLotto) == Boolean.FALSE) { | ||
| //System.out.println("보너스 x"); | ||
| THIRD++; | ||
| break; | ||
| } | ||
| case 6: | ||
| FIRST++; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| private double getResultMoney(){ | ||
| return FIRST*2000000000 + SECOND*30000000 + THIRD*1500000 + FORTH*50000 + FIVTH*5000; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package lotto.Domain; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class LottoResult { | ||
| public LottoResult(){} | ||
|
|
||
| public long getLottoResult(List<Integer> LottoList,List<Integer> WinningLotto){ | ||
|
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. 로또의 등수를 계산하는 로직은 저는 개인적으로 비즈니스 로직이라고 생각해서 따로 Service 패키지를 생성해서 Service가 비즈니스 로직인 로또 구매, 로또 당첨 결과 계산을 맡아서 할 수 있도록 하였습니다! 만약 비즈니스 로직을 Service로 따로 분리하는게 후에 기능이 추가되거나 할 때, 확장성 측면에서 더 좋다고 생각해요! |
||
| return LottoList.stream() | ||
|
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. stream을 이용해서 잘 작성하신 것 같아요! |
||
| .filter(WinningLotto::contains) | ||
| .count(); | ||
|
|
||
| } | ||
| public Boolean getBounsResult(Integer BounNum,List<Integer> WinningLotto){ | ||
| return WinningLotto.contains(BounNum); | ||
| } | ||
|
|
||
| public double getRateOfReturn(double ResultMoney,double LottoMoney){ //수익률 계산 | ||
| double a = (ResultMoney/LottoMoney)*100; | ||
| return Math.round(a*10.0)/10.0; | ||
| } | ||
|
|
||
| public Integer getResult(List<Integer> LottoList,List<Integer> WinningLotto){ //개별 로또의 결과 확인 | ||
| LottoResult lottoResult = new LottoResult(); | ||
| return (int)lottoResult.getLottoResult(LottoList,WinningLotto); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package lotto.Domain; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class RandomLotto { | ||
| public RandomLotto(){} | ||
|
|
||
| public List<Integer> getRandomlotto(){ | ||
| return Randoms.pickUniqueNumbersInRange(1,45,6); | ||
| } | ||
|
|
||
| public static List<Integer> setRandomLotto(){ //단일 로또 생성 | ||
| RandomLotto randomLotto = new RandomLotto(); | ||
| Lotto lotto = new Lotto(randomLotto.getRandomlotto()); | ||
| return lotto.getLotto(); | ||
| } | ||
|
|
||
| public static List<List> setRandomLottoList(Integer Amount){ //Amount개의 로또 생성 | ||
| List<List> RandomLottoList = new ArrayList<>(); | ||
| for(int i=0;i<Amount;i++){ | ||
| RandomLottoList.add(setRandomLotto()); | ||
| Collections.sort(RandomLottoList.get(i)); | ||
| } | ||
| return RandomLottoList; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package lotto.View; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
| import lotto.Domain.Lotto; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class InOut { | ||
| public InOut(){} | ||
|
|
||
| public List<Integer> InWinningLotto(){ | ||
|
|
||
| System.out.println("당첨 번호를 입력해 주세요 "); | ||
| String[] input = Console.readLine().split(","); | ||
| List<Integer> WinningLotto = new ArrayList<>(); | ||
| for(int i=0;i<6;i++){ | ||
| WinningLotto.add(Integer.parseInt(input[i])); | ||
| } | ||
|
|
||
| return new Lotto(WinningLotto).getLotto(); | ||
| } | ||
| public Integer InLottoMoney(){ | ||
| System.out.println("구입 금액을 입력해 주세요 "); | ||
| return Integer.parseInt(Console.readLine()); | ||
|
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 Integer InBonusNum(){ | ||
| System.out.println("보너스 번호를 입력해 주세요"); | ||
| return Integer.parseInt(Console.readLine()); | ||
| } | ||
|
|
||
| public void OutResultStatistics(int FIRST,int SECOND,int THIRD,int FORTH,int FIVTH,double RateOfReturn){ //로또 최종 통계 출력 | ||
|
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. 이 부분도 View에게 결과만 넘겨주고 출력은 View에서 해주는게 더 좋을 것 같습니다! |
||
| System.out.println("당첨 통계"); | ||
| System.out.println("---"); | ||
| System.out.println("3개 일치 (5,000원) - "+FIVTH+"개"); | ||
| System.out.println("4개 일치 (50,000원) - "+FORTH+"개"); | ||
| System.out.println("5개 일치 (1,500,000원) - "+THIRD+"개"); | ||
| System.out.println("5개 일치, 보너스 볼 일치(30,000,000원) - "+SECOND+"개"); | ||
| System.out.println("6개 일치 (2,000,000,000원) - "+FIRST+"개"); | ||
| System.out.println("총 수익률은 "+RateOfReturn+"% 입니다"); | ||
| } | ||
|
|
||
| public void OutLottoList(List<List> MyRandomLottoList){ //랜덤으로 생성된 로또 출력 | ||
| for(List<Integer> myList : MyRandomLottoList){ | ||
| System.out.println(myList); | ||
| } | ||
| } | ||
|
|
||
| public void OutLottoAmount(int LottoAmount){ | ||
| System.out.println(LottoAmount+"개를 구매하셨습니다"); | ||
| } | ||
|
|
||
| } | ||
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.
여기서도 1000으로 나누어떨어지지 않는 경우에 대해 검증하면 더 좋을 것 같습니다!