Skip to content
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

๐Ÿ”€ [hanse & sally] ๋กœ๋˜ 2๋‹จ๊ณ„ - ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ถ”๊ฐ€ #45

Open
wants to merge 15 commits into
base: sally-ksh
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f0573f7
feat : Input ํด๋ž˜์Šค, Main ํด๋ž˜์Šค
rkolx Feb 24, 2022
d069d61
refactor : ๋‹น์ฒจ๋ฒˆํ˜ธ ๋ชจ์Œ ํด๋ž˜์Šค ๋ฐ ํด๋ž˜์Šค ๋ช… ์ˆ˜์ •
rkolx Feb 24, 2022
8d41897
feat : ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ถ”๊ฐ€
rkolx Feb 24, 2022
d69a5ee
refactor: ๋กœ๋˜ ๊ฒฐ๊ณผ ๋กœ์ง ๋ฆฌํŒฉํ† ๋ง
sally-ksh Feb 24, 2022
141f826
refactor: ๋ณด๋„ˆ์Šค๋ณผ ์ถ”๊ฐ€ ์‚ฌํ•ญ ์ถ”์ƒํ™”
sally-ksh Feb 24, 2022
696896e
refactor: LottoPlay ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ๋ถ„๋ฆฌ
sally-ksh Feb 24, 2022
ec5169b
feat: ํŒจํ‚ค์ง€ ๋ถ„๋ฆฌ
sally-ksh Feb 24, 2022
d7ca355
refactor: ๋ณด๋„ˆ์Šค๋ณผ ์ƒ์†์œผ๋กœ ๋ณ€๊ฒฝ
sally-ksh Feb 25, 2022
72bc927
fix
sally-ksh Feb 25, 2022
b9df53d
refactor : ๋กœ๋˜ ๋‹ด๋Š” ๋ฉ”์„œ๋“œ ์—ญํ• ์— ๋”ฐ๋ผ ๋ถ„๋ฆฌ
rkolx Feb 25, 2022
7ac4a2b
docs : 2๋‹จ๊ณ„ ์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๊ฒŒ RADME.md ์ˆ˜์ •
rkolx Feb 25, 2022
ee3deaa
refacfor : gettotalLottos ๋ฉ”์„œ๋“œ ๋ถ„๋ฆฌ
rkolx Feb 25, 2022
79bfcec
refactor : ๋™์ž‘ ํด๋ž˜์Šค๋ช… ์ˆ˜์ •
rkolx Feb 25, 2022
73388b2
refactor: ๋ฆฌ๋ทฐ ๋ฐ˜์˜
sally-ksh Feb 26, 2022
8271d2d
Merge pull request #1 from sally-ksh/sally-step2
sally-ksh Feb 26, 2022
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
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@

#### ๊ธฐ๋Šฅ์š”๊ตฌ์‚ฌํ•ญ

- [x] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋กœ๋˜๋ฅผ ๋ฐœ๊ธ‰ํ•ด์•ผ ํ•œ๋‹ค.
- [x] ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1000์›์ด๋‹ค.
- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„์„œ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•œ๋‹ค.
- [x] ๊ธฐ๋Œ€ ์ˆ˜์ต์€ ๋™์ž‘ ์˜ˆ์‹œ๋ฅผ ์ฐธ๊ณ ํ•˜์ž.
- [x] 2๋“ฑ์„ ์œ„ํ•ด ์ถ”๊ฐ€ ๋ฒˆํ˜ธ๋ฅผ ํ•˜๋‚˜ ๋” ์ถ”์ฒจํ•œ๋‹ค. ๋‹น์ฒจ ํ†ต๊ณ„์— 2๋“ฑ๋„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.



#### ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ์‚ฌํ•ญ

- [x] indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 1๋‹จ๊ณ„๋กœ ๊ตฌํ˜„ํ•œ๋‹ค.
- [x] depth์˜ ๊ฒฝ์šฐ if๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ 1๋‹จ๊ณ„์˜ depth๊ฐ€ ์ฆ๊ฐ€ํ•œ๋‹ค. if๋ฌธ ์•ˆ์— while๋ฌธ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด depth๊ฐ€ 2๋‹จ๊ณ„๊ฐ€ ๋œ๋‹ค.
- [x] else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ๋ผ.
- [x] ๋ฉ”์†Œ๋“œ์˜ ํฌ๊ธฐ๊ฐ€ ์ตœ๋Œ€ 10๋ผ์ธ์„ ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค.
- [x] method๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ.
- [x] ArrayList๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ตฌํ˜„ํ•œ๋‹ค.

- [x] enum์„ ์ ์šฉํ•ด ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๊ตฌํ˜„ํ•œ๋‹ค.

#### ์ถœ๋ ฅ ๊ฒฐ๊ณผ

<img src="https://user-images.githubusercontent.com/92699009/155276313-d1260c5c-de96-4875-9a05-bf43b59c10b9.png">
<img src="https://user-images.githubusercontent.com/92699009/155632776-f8de735e-2021-4985-8104-3e79c7f7317c.PNG">
31 changes: 31 additions & 0 deletions src/LottoApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import static views.Input.*;
import static views.Output.*;

import java.util.List;

import domains.users.LottoMachine;
import domains.users.Lottos;
import domains.winnings.Ranking;
import domains.users.UserLotto;
import views.PurchasedLotto;

public class LottoApplication {
private static LottoMachine lottoMachine = new LottoMachine();
private static Lottos lottos = new Lottos();
private static UserLotto userLotto = new UserLotto(lottoMachine, lottos);
Comment on lines +14 to +16

Choose a reason for hiding this comment

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

์ด ๋ถ€๋ถ„์„ ์–ด๋–ป๊ฒŒ ๊ฐœ์„ ํ•˜๋ฉด ์ข‹์„์ง€ 3๋‹จ๊ณ„์—์„œ ๊ณ ๋ฏผํ•ด์ฃผ์„ธ์š”~

ํžŒํŠธ: LottoGame ๋ถ„๋ฆฌ, ์˜์กด์„ฑ ์ฃผ์ž…

Choose a reason for hiding this comment

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

์œผ-์Œ.... ์–ด๋ ต์ง€๋งŒ, ์•Œ ๊ฒƒ๋„ ๊ฐ™๊ณ ... @_@๊ณ ๋ฏผ ํ•ด์„œ ๊ฐœ์„ ๋˜๋„๋ก ๋…ธ๋ ฅํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
3๋‹จ๊ณ„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์˜คํ† ,์ˆ˜๋™๋งŒ di๋กœ ํ–ˆ๋Š”๋ฐ๋„, ๋ณด์ง€ ๋ชปํ•œ ๋ถ€๋ถ„์ด ์žˆ๋Š” ๊ฑฐ ๊ฐ™์•„์š”.
์•Œ๋ ค์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.๐Ÿฅ‡


public static void main(String[] args) {
PurchasedLotto purchasedLotto = purchaseLotto();

List<List<Integer>> totalLottos = userLotto.getTickets(purchasedLotto);

Choose a reason for hiding this comment

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

List<List<T>> ์™€ 2์ฐจ์› ๋ฐฐ์—ด๊ณผ์˜ ์ฐจ์ด์ ์ด ๋ฌด์—‡์ผ๊นŒ์š”?

Copy link
Member Author

Choose a reason for hiding this comment

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

2์ฐจ์› ๋ฐฐ์—ด์˜ ์ฐจ์ด์ ๊ณผ ๋ฆฌ์ŠคํŠธ์˜ ์žฅ์ ์„ ์•Œ๊ณ  ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ํƒํ•ด์„œ ์‚ฌ์šฉํ•œ๊ฑด์ง€์— ๋Œ€ํ•œ๊ฑธ ๋ง์”€ํ•˜์‹œ๋Š” ๊ฑธ๊นŒ์š”? ์–ด๋–ค ์˜๋ฏธ์ธ์ง€ ๋ชฐ๋ผ ์—ฌ์ญ™๋‹ˆ๋‹คใ… ใ… 

Choose a reason for hiding this comment

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

๋„ค ์ฐจ์ด์ ์ด ์—†๋‹ค๋Š”๊ฒŒ ์ •๋‹ต์ด์—ˆ์–ด์š”. ใ…Žใ…Ž
๋ฆฌํŒฉํ† ๋ง์„ ๋ถ€ํƒ๋“œ๋ฆฐ๋‹ค๋Š” ์˜๋ฏธ์ด๊ธฐ๋„ ํ–ˆ๊ตฌ์š”~

showLottos(totalLottos);

List<Integer> inputValueOfWinningNumbers = inputWinningNumbers();
int bonusNumber = getBonusNumber();

Ranking ranking = userLotto.getRankingFromWinningNumbers(inputValueOfWinningNumbers, bonusNumber);

Choose a reason for hiding this comment

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

inputValueOfWinningNumbers, bonusNumber ๋Š” ๋‹จ์ˆœํžˆ ํŒŒ๋ผ๋ฉ”ํ„ฐ๋กœ ์ „๋‹ฌ๋˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜๋“ค์ด๊ตฐ์š”.
๊ทธ๋ ‡๋‹ค๋ฉด ๋ณ„๋„์˜ ์„ ์–ธ ์—†์ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ•ด๋„ ๋˜์ง€ ์•Š์„๊นŒ ์‹ถ๋„ค์š”.

Ranking ranking = userLotto.getRankingFromWinningNumbers(inputWinningNumbers(), getBonusNumber());

Copy link

@sally-ksh sally-ksh Feb 26, 2022

Choose a reason for hiding this comment

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

๊ฐ์ฒดํƒ€์ž… ๋ฐ˜ํ™˜์˜ ๊ฒฝ์šฐ๋Š” ๋ช…์‹œ์ ์œผ๋กœ ์ ์–ด์ฃผ๋Š” ๊ฒŒ ์•ˆ์ •์„ฑ ๋“ฑ์—์„œ ์ข‹๋‹ค๊ณ  ์•Œ๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
์‚ฌ์‹ค...์œ„ ๊ฒฝ์šฐ์ฒ˜๋Ÿผ ๋™์ผํ•œ ์˜๋ฏธ๊ฐ€ ๋‹ด๊ธด ๋ฉ”์„œ๋“œ๋ช…ํ•˜๊ณ  ์ฐธ์กฐ๋ณ€์ˆ˜๋ช… ๋‘ ๋ฒˆ ๊ณ ๋ คํ•˜๋Š”๊ฒŒ ์ •๋ง ์˜๋ฏธ ์—†๊ธฐ๋„ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

ํ˜น์‹œ ๋ฌธ์ œ๋˜๊ฑฐ๋‚˜ ์•ˆ ์ข‹์€ ์ด์œ ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ตฌ์ฒด์ ์œผ๋กœ ์•Œ๊ณ  ์‹ถ์–ด์„œ์š”.
์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

getResultOfLotto(ranking, purchasedLotto.getPurchaseAmount());

scanClose();
}
}
44 changes: 0 additions & 44 deletions src/Main.java

This file was deleted.

92 changes: 0 additions & 92 deletions src/domains/Ranking.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/domains/Winnings.java

This file was deleted.

11 changes: 9 additions & 2 deletions src/domains/Lotto.java โ†’ src/domains/users/Lotto.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domains;
package domains.users;

import java.util.Collections;
import java.util.List;
Expand All @@ -23,7 +23,7 @@ public List<Integer> numbers() {
return this.sixNumbers;
}

public int numberOfWinnings(List<Integer> winningNumbers){
public int countNumberOfWinnings(List<Integer> winningNumbers){

Choose a reason for hiding this comment

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

stream ์‚ฌ์šฉํ•ด์„œ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์„ ๊ฑฐ ๊ฐ™๋„ค์š”

int count = 0;
for (Integer winningNumber : winningNumbers) {
count = getCount(count, winningNumber);
Expand All @@ -37,4 +37,11 @@ private int getCount(int count, Integer winningNumber) {
}
return count;
}

public boolean getBonus(int bonusNumber) {
if (sixNumbers.contains(bonusNumber)){
return true;
}
return false;

Choose a reason for hiding this comment

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

์ด๋ ‡๊ฒŒ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”

Suggested change
if (sixNumbers.contains(bonusNumber)){
return true;
}
return false;
return sixNumbers.contains(bonusNumber));

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domains;
package domains.users;

Choose a reason for hiding this comment

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

ํŒจํ‚ค์ง€๋ช…์— ๋ณต์ˆ˜ํ˜•์„ ์ž˜ ์“ฐ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Copy link

@sally-ksh sally-ksh Feb 26, 2022

Choose a reason for hiding this comment

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

ํ˜„์žฌ๋Š” ํ•œ๋ช…์˜ ์ž…๋ ฅ๋งŒ ๋ฐ›์•„์„œ ๋ณต์ˆ˜ํ˜• ์“ฐ์ง€ ์•Š๋Š”๊ฒŒ ๋งž๊ณ , ์Šคํ”„๋ง์˜ ๊ฒฝ์šฐ์—๋Š” ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๋‹ค๋ฃจ๋‹ˆ ๋ณต์ˆ˜ํ˜•์„ ์“ฐ๋Š”๊ฒŒ ๋งž๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ ๊นŒ์š”?
์Šคํ”„๋ง ๊ฐ•์˜์—์„œ ํŒจํ‚ค์ง€๋ช…์— ๋ณต์ˆ˜ํ˜•์œผ๋กœ ์“ฐ๋ผ๊ณ  ํ•˜์…จ์–ด์„œ,.. ์ข€ ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ์•Œ๊ณ  ์ •๋ฆฌํ•˜๊ณ ์ž ์งˆ๋ฌธ ํ•ฉ๋‹ˆ๋‹ค.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Choose a reason for hiding this comment

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

์ผ๋‹จ domains ๊นŒ์ง€๋Š” ์ž˜ ์ดํ•ด๊ฐ€ ๋˜์—ˆ๊ตฌ์š”,
users ๊ฐ€ ๋ณต์ˆ˜ํ˜•์ด ๋œ ์ด์œ ๋ฅผ ์•Œ๊ณ  ์‹ถ์—ˆ์–ด์š”. ๋ณต์ˆ˜ํ˜•์ด ๋˜๋ฉด ์•ˆ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ตฌ์š”.
user ๋ผ๋Š” ์ผ๋ฐ˜์ ์ธ ๊ฐœ๋…, ํ˜น์€ ํ”„๋กœ๊ทธ๋žจ์  ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ๋“ค์˜ ์ง‘ํ•ฉ์ด๋ผ users ๋ผ๋Š” ๊ฑด ์ข€ ์–ด์ƒ‰ํ•˜๋‹ค๊ณ  ๋ดค๊ฑฐ๋“ ์š”. ์šฐ๋ฆฌ๊ฐ€ ์ถ”์ƒํ™”ํ•ด์•ผ ํ•  ๊ฐœ๋… ์ž์ฒด๋Š” user ๋ผ๊ณ  ํ‘œํ˜„๋˜๋Š”๊ฒŒ ๋งž๋‹ค๊ณ  ๋ด์„œ์š”.
์Šคํ”„๋ง ๊ฐ•์˜์—์„œ ํŒจํ‚ค์ง€๋ช…์— ๋Œ€ํ•ด ์–ด๋–ป๊ฒŒ ๋‹ค๋ฃจ๊ณ  ์žˆ๋Š”์ง€๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๋„ค์š”.

Choose a reason for hiding this comment

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

๋„ค, ๋ง์”€ํ•ด ์ฃผ์‹  ๋ถ€๋ถ„์„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์„๊ฑฐ ๊ฐ™์•„์š”.
์ €๋Š” ๋‹จ์ˆœ ์ง€์‹์ด์—ˆ๋Š”๋ฐ, ์„ค๋ช… ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ๋Š” ๋‹จ์ˆ˜ํ˜•์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค. :)


import java.util.ArrayList;
import java.util.Collections;
Expand Down
33 changes: 23 additions & 10 deletions src/domains/Lottos.java โ†’ src/domains/users/Lottos.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package domains;

import static java.util.stream.Collectors.*;
package domains.users;

import java.util.ArrayList;
import java.util.List;

import domains.winnings.BonusWinningNumbers;
import domains.winnings.Ranking;

public class Lottos {
public static final int MINIMUM_NUMBER_OF_WINNING = 3;
private ArrayList<Lotto> lottos = new ArrayList<>();
Expand All @@ -14,11 +15,18 @@ public Lottos() {
}

public List<List<Integer>> getTotalLottos(ArrayList<ArrayList<Integer>> tickets) {
toLottos(tickets);

return getPurchasedLottos();
}

private void toLottos(ArrayList<ArrayList<Integer>> tickets) {
for (ArrayList<Integer> ticket : tickets) {
this.purchased(ticket);
}
}

private List<List<Integer>> getPurchasedLottos() {

Choose a reason for hiding this comment

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

๋‹น์ฒจ๋ฒˆํ˜ธ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด๊ด€ํ•  ๋งŒํ•œ ๊ฐ์ฒด๋ฅผ ์„ค๊ณ„ํ•ด์„œ ๊ทธ ๊ฐ์ฒด์˜ ๋ฆฌ์ŠคํŠธ๋กœ ์ „๋‹ฌํ•ด์ฃผ๋ฉด ๋” ์ข‹์„ํ…๋ฐ์š”?

Copy link

@sally-ksh sally-ksh Feb 26, 2022

Choose a reason for hiding this comment

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

๋„ต, ๋งž์Šต๋‹ˆ๋‹ค.

List<List<Integer>> purchasedLottos = new ArrayList<>();
for (Lotto lotto : this.lottos) {
List<Integer> numbers = lotto.numbers();
Expand All @@ -32,12 +40,17 @@ private void purchased(ArrayList<Integer> pickedNumber){
this.lottos.add(lotto);
}

public List<Integer> numberOfWinningAboveThree(List<Integer> winningNumbers) {
List<Integer> resultOfLottos = this.lottos.stream()
.mapToInt(lotto -> lotto.numberOfWinnings(winningNumbers))
.filter(value -> value >= MINIMUM_NUMBER_OF_WINNING)
.boxed()
.collect(toList());
return resultOfLottos;
public Ranking getNumberOfWinningAboveThree(BonusWinningNumbers winningNumbers) {
Ranking ranking = new Ranking();
List<Integer> winning = winningNumbers.getNumbers();

for (Lotto lotto : lottos) {
int winningCount = lotto.countNumberOfWinnings(winning);
if (winningCount >= MINIMUM_NUMBER_OF_WINNING) {
boolean checkedBonus = lotto.getBonus(winningNumbers.getBonus());
ranking.record(checkedBonus, winningCount);
}

Choose a reason for hiding this comment

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

Lotto ๊ฐ€ ๊ฐ–๊ณ  ์žˆ๋Š” ๋‹น์ฒจ ๋ฒˆํ˜ธ ๊ฐฏ์ˆ˜๋ฅผ ๋ฌผ์–ด๋ณด๊ณ , ๋ณด๋„ˆ์Šค๊นŒ์ง€ ๊บผ๋‚ด์™€์„œ ์ฒดํฌํ•œ ๋‹ค์Œ Ranking ๊ฐ์ฒด์— set์„ ํ•ด์ฃผ๊ณ  ์žˆ๊ตฐ์š”.
๊ทธ๋Ÿฌ์ง€ ๋ง๊ณ  Lotto ๊ฐ์ฒด๊ฐ€ ์ง์ ‘ Ranking ๊ฒฐ๊ณผ๊ฐ’์„ ์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ฐœ์„ ํ•ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ์š”?

Choose a reason for hiding this comment

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

์ค‘๊ฐ„์— WinningNumber๋กœ ๋ถ„๋ฆฌํ•˜๊ณ , Ranking ๋ฐ˜ํ™˜ ๋“ฑ ๊ฐœ์„  ํ•˜๋ฉด์„œ, ์‹œ์•ผ๊ฐ€ ์ข์•„์ง€๊ณ , ์ข€ ๋” ๋ถ„๋ช…ํ•˜๊ฒŒ ์ •๋ฆฌํ•˜์ง€ ๋ชป ํ•œ๊ฑฐ ๊ฐ™์•„์š”.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

}
return ranking;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domains;
package domains.users;

public class Money {
private static final String WON = "์›";
Expand Down
29 changes: 29 additions & 0 deletions src/domains/users/UserLotto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package domains.users;

import java.util.ArrayList;
import java.util.List;

import domains.winnings.BonusWinningNumbers;
import domains.winnings.Ranking;
import views.PurchasedLotto;

public class UserLotto {
private final LottoMachine lottoMachine;
private final Lottos lottos;

public UserLotto(LottoMachine lottoMachine, Lottos lottos) {
this.lottoMachine = lottoMachine;
this.lottos = lottos;
}

public List<List<Integer>> getTickets(PurchasedLotto purchasedLotto) {
ArrayList<ArrayList<Integer>> tickets = lottoMachine.getTicket(purchasedLotto.getNumberOfTicket());

Choose a reason for hiding this comment

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

java.util.ArrayList ์—๋งŒ ์กด์žฌํ•˜๋Š” ๋ฉ”์„œ๋“œ๋‚˜ ๋กœ์ง์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ฐ•๊ฒฐํ•ฉ๋˜์–ด์•ผ ํ•  ํŠน๋ณ„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด ํ•ญ์ƒ List<T> ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
์ด์œ ๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ์š”... https://stackoverflow.com/questions/9852831/polymorphism-why-use-list-list-new-arraylist-instead-of-arraylist-list-n ๋ฅผ ์ฐธ๊ณ ํ•ด๋ณด์„ธ์š”.

Copy link

@sally-ksh sally-ksh Feb 26, 2022

Choose a reason for hiding this comment

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

์š”๊ตฌ์‚ฌํ•ญ ์ค‘์— "ArrayList๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ตฌํ˜„ํ•œ๋‹ค." ๊ฐ€ ์žˆ์—ˆ๋Š”๋ฐ ๋‹จ์ˆœํ•˜๊ฒŒ ๋ฐ˜ํ™˜ํƒ€์ž… ๊นŒ์ง€ ์จ์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ž‘์—…ํ–ˆ๋˜๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ด๋ฒˆ์— ํŽ˜์–ด ํ•˜๋ฉด์„œ, ์œ„์—์„œ ์–ธ๊ธ‰๋œ ๋ถ€๋ถ„๋“ค๋„ ๊ทธ๋ ‡๊ณ 
์ฒด๋ ฅ๊ณผ ์ง‘์ค‘๋ ฅ์ด ๋งŽ์ด ๋–จ์–ด์ ธ์„œ ๋๊นŒ์ง€ ์ •๋ฆฌ ์•ˆ ํ•œ ๋ถ€๋ถ„๋“ค์ด ์žˆ์—ˆ๋Š”๋ฐ,
์ข€๋” ์ง‘์ค‘ํ•ด์„œ ๊ฐœ์„ ํ•˜๋„๋ก ์ด๋Œ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋˜ ๋ณด๋‹ค ์ข‹์€ ์ง€์‹ ์•Œ๊ฒŒ ๋œ ๊ฑฐ ๊ฐ™์•„์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

return lottos.getTotalLottos(tickets);
}

public Ranking getRankingFromWinningNumbers(List<Integer> inputValueOfWinningNumbers, int bonusNumber) {
BonusWinningNumbers winningNumbers = new BonusWinningNumbers(inputValueOfWinningNumbers, bonusNumber);
Ranking ranking = lottos.getNumberOfWinningAboveThree(winningNumbers);
return ranking;
}
}
16 changes: 16 additions & 0 deletions src/domains/winnings/BonusWinningNumbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package domains.winnings;

import java.util.List;

public class BonusWinningNumbers extends WinningNumbers{
private final int bonus;

public BonusWinningNumbers(List<Integer> winningNumbers, int bonus) {
super(winningNumbers);
this.bonus = bonus;
}

public int getBonus() {
return bonus;
}
}
Loading