-
Notifications
You must be signed in to change notification settings - Fork 7
[로또 게임] 양재승 과제 제출합니다. #5
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 18 commits
dc4c9f2
7dd70d8
01b03ae
b3d10cf
7a90b25
a296f4b
0b08a53
f9a2b65
335b415
9f153e6
c88e085
eef5920
ba6db28
65e3e1c
7274c48
5f9c35e
f83b98e
7abc21e
92ce4e9
d206c3a
df5c7c7
d6b8e7f
6e68eb6
d44a083
8872a11
4121a02
7c8f400
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,10 @@ | ||
| package lotto; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
|
|
||
| LottoGame lottoGame = new LottoGame(); | ||
| lottoGame.run(); | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package lotto; | ||
|
|
||
| public class Calculator { | ||
| LottoList lottoList; | ||
| WinningNumbers winningNumbers; | ||
|
|
||
| int countThree = 0, countFour = 0, countFive = 0, countSix = 0, countFiveAndBonus = 0; | ||
| int totalIncome = 0; | ||
|
|
||
| Calculator(LottoList lottoList, WinningNumbers winningNumbers){ | ||
| this.lottoList = lottoList; | ||
| this.winningNumbers = winningNumbers; | ||
| calculateCorrectCount(); | ||
| } | ||
|
|
||
| public void calculateCorrectCount(){ | ||
| for(int i=0; i<lottoList.lottos.length; i++) { | ||
| int correctCount = lottoList.lottos[i].calculateCorrectCount(winningNumbers.winningNumberslist); | ||
| boolean correctBonus = lottoList.lottos[i].calculateBonusNumber(winningNumbers.bonusNumber); | ||
|
|
||
| countUp(correctCount, correctBonus); | ||
| } | ||
| } | ||
|
|
||
| private void countUp(int correctCount, boolean correctBonus){ | ||
| switch (correctCount) { | ||
| case 3: | ||
| countThree++; | ||
| totalIncome += 5000; | ||
| break; | ||
| case 4: | ||
| countFour++; | ||
| totalIncome += 50000; | ||
| break; | ||
| case 5: | ||
| countFive++; | ||
| totalIncome += 1500000; | ||
| break; | ||
| case 6: | ||
| countSix++; | ||
| totalIncome += 2000000000; | ||
| break; | ||
|
|
||
| } | ||
|
|
||
| if(correctCount == 6 && correctBonus == true){ | ||
| countFiveAndBonus++; | ||
| totalIncome += 30000000; | ||
| } | ||
| } | ||
|
|
||
| public void printResult(){ | ||
| System.out.println("당첨 통계"); | ||
| System.out.println("---"); | ||
| System.out.println("3개 일치 (5,000원) - " + countThree + "개"); | ||
| System.out.println("4개 일치 (50,000원) - " + countFour + "개"); | ||
| System.out.println("5개 일치 (1,500,000원) - " + countFive + "개"); | ||
| System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원) - " + countFiveAndBonus + "개"); | ||
| System.out.println("6개 일치 (2,000,000,000원) - " + countSix + "개"); | ||
| } | ||
|
||
|
|
||
| public void printIncomeRate(int coin){ | ||
| double incomeRateTemp = ((double)totalIncome / (double)(coin * 1000))*100; | ||
| double incomeRate = Math.round(incomeRateTemp*100)/100.0; | ||
| System.out.println("총 수익률은 " + incomeRate + "%입니다."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package lotto; | ||
|
|
||
| import static lotto.Message.*; | ||
| import java.util.List; | ||
|
|
||
| public class ExceptionController { | ||
|
|
||
| public static void noIntegerValueException(String Numbers){ | ||
| for(int i=0; i<Numbers.length(); i++){ | ||
| int isIntger = Numbers.charAt(i) - '0'; | ||
| if(isIntger<0 || isIntger>9){ | ||
| System.out.println(NOT_INTAGER_ERROR_MESSAGE); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void noValidAmountException(String amount){ | ||
| if(Integer.parseInt(amount)%1000 != 0){ | ||
| System.out.println(NOT_THOUSAND_ERROR_MESSAGE); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
||
|
|
||
| public static void noValidLottoNumberException(int number){ | ||
| if(number<1 || number>45){ | ||
| System.out.println(NOT_OUTRANGE_NUMBER_ERROR_MESSAGE); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| public static void overlapNumberException(List<Integer> winningNumberList, int correctInteger){ | ||
| if(winningNumberList.contains(correctInteger)){ | ||
| System.out.println(OVERLAP_NUMBER_ERROR_MESSAGE); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } | ||
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.
클린코드의 영역인데 switch case문은 지양하는 편이 좋습니다.