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

πŸš€ 4단계 - 둜또(μˆ˜λ™) #1004

Open
wants to merge 100 commits into
base: joecp17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
671f06b
fix : kotest markTime 이슈 해결을 μœ„ν•œ 버전 λ³€κ²½
JoeCP17 Nov 9, 2023
f9a331c
feat : λ¬Έμžμ—΄ 식 도메인 ( Expression ) κ΅¬ν˜„
JoeCP17 Nov 9, 2023
14be18e
feat : 계산기 도메인 ( Calculator ) κ΅¬ν˜„
JoeCP17 Nov 9, 2023
0a66c23
feat : μ΅œμ’… λ‹΅ 도메인 ( FinalResult ) 객체 κ΅¬ν˜„
JoeCP17 Nov 9, 2023
cc8a3d9
test : λ¬Έμžμ—΄ 도메인 ( Expression ) ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 9, 2023
d87ee8b
test : 계산기 도메인 ( Calculator ) 도메인 ν…ŒμŠ€νŠΈ 진행
JoeCP17 Nov 9, 2023
e46cf58
docs : Readme μž‘μ„±
JoeCP17 Nov 9, 2023
06763fe
Merge branch 'step1' into main
JoeCP17 Nov 10, 2023
74ce73d
feat : ꡬ맀 κΈˆμ•‘ 도메인 ( BuyAmount ) 생성
JoeCP17 Nov 12, 2023
fec11ed
feat : 둜또 ν‹°μΌ“ 도메인 ( LottoTickets ) 생성
JoeCP17 Nov 12, 2023
51d49f7
feat : 둜또 상점 ( LottoStore ) 도메인 생성
JoeCP17 Nov 12, 2023
753e16d
feat : 둜또 κ²°κ³Ό 도메인과 맀치 계산 Enum 생성
JoeCP17 Nov 12, 2023
40ad192
feat : 둜또 번호 도메인 ( Number, Numbers ) 생성
JoeCP17 Nov 12, 2023
b50480c
feat : 둜또 UI View 생성
JoeCP17 Nov 12, 2023
5dd6702
feat : 둜또 싀행을 μœ„ν•œ Main 클래슀 생성
JoeCP17 Nov 12, 2023
4cf6c5d
test : 둜또 ꡬ맀 κΈˆμ•‘ 도메인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 12, 2023
9ea8a0e
test : 둜또 ν‹°μΌ“ 도메인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 12, 2023
65184a9
test : 둜또 ν‹°μΌ“ λ„˜λ²„ 도메인 ( Number, Numbers ) ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 12, 2023
1d00bad
test : 둜또 κ²°κ³Ό 도메인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 12, 2023
8fcae38
test : 둜또 상점 도메인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Nov 12, 2023
b684a56
docs : 둜또 과제 README μž‘μ„±
JoeCP17 Nov 12, 2023
33bb4c7
chore : μ›ν™œν•œ νŒ¨ν‚€μ§€ 관리λ₯Ό μœ„ν•œ 이전 ν•­λͺ© νŒ¨ν‚€μ§€ 이동
JoeCP17 Nov 12, 2023
bd4649b
Merge branch 'joecp17' into step2
JoeCP17 Nov 12, 2023
a93a55a
chore : step1 쀑볡 νŒ¨ν‚€μ§€λ“€ 제거
JoeCP17 Nov 14, 2023
5150c5a
refactor : 계산기 도메인 ( Calculator ) λ‚΄, λ¬Έμžμ—΄ 계산 λ©”μ„œλ“œ μˆ˜μ •
JoeCP17 Nov 14, 2023
2e4789b
refactor : λ¬Έμžμ—΄ 식 도메인 ( Expression ) λ‚΄, 음수 검증 private method μΆ”κ°€
JoeCP17 Nov 14, 2023
19e267b
refactor : of ν•¨μˆ˜ 제거λ₯Ό ν†΅ν•œ ν…ŒμŠ€νŠΈ μ½”λ“œ λ‚΄, 생성 둜직 μˆ˜μ •
JoeCP17 Nov 14, 2023
240084d
refactor : Numbers 도메인을 Lotto λ„λ©”μΈμœΌλ‘œ μˆ˜μ • 및 λ‚΄λΆ€ λ¦¬νŒ©ν† λ§ 진행
JoeCP17 Nov 14, 2023
2172915
refactor : κ΅¬λ§€κΈˆμ•‘ 도메인 ( BuyAmount ) λ¦¬νŒ©ν† λ§ 진행
JoeCP17 Nov 14, 2023
c297adf
refactor : 숫자 도메인 ( Number ) λ‚΄, private 제거 및 of , get ν•¨μˆ˜ 제거
JoeCP17 Nov 14, 2023
5af7f10
feat : 둜또 당첨확인 도메인 ( WinningLotto ) 생성
JoeCP17 Nov 14, 2023
8d1743e
refactor : 둜또 μ΅œμ’… κ²°κ³Ό 도메인 ( LottoResult ) private 제거 및 of ν•¨μˆ˜ 제거
JoeCP17 Nov 14, 2023
125967f
refactor : 둜또 상점 ( LottoStore ) λ‚΄ κ²°κ³Ό 확인 ν•¨μˆ˜ 둜직 μˆ˜μ • 및 μˆ˜λŸ‰ 체크 ν•¨μˆ˜ μˆ˜μ •
JoeCP17 Nov 14, 2023
cbdf403
refactor : 둜또 λ°œκΈ‰ ν‹°μΌ“λ“€ ( LottoTickets ) 도메인 λ‚΄, 번호 생성 ν•¨μˆ˜ μˆ˜μ • 및 private , …
JoeCP17 Nov 14, 2023
43d2600
refactor : private, of λ©”μ„œλ“œ 제거λ₯Ό ν†΅ν•œ ν…ŒμŠ€νŠΈ μ½”λ“œ μˆ˜μ •
JoeCP17 Nov 14, 2023
a9eecfe
refactor : 좜λ ₯ View λ‚΄, νŒŒλΌλ―Έν„° λ‚΄ 도메인 λΆ€λΆ„ μˆ˜μ •
JoeCP17 Nov 14, 2023
1d67b02
test : 이전 Step1 λ‚΄, 음수 포함 식 κ΄€λ ¨ ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±
JoeCP17 Nov 14, 2023
f14f18b
feat : 각 μ „λž΅λ³„ 숫자 생성을 μœ„ν•œ Enum 클래슀 생성
JoeCP17 Nov 14, 2023
027b1c2
test : 숫자 생성기 ( Number Generator ) 생성을 ν†΅ν•œ ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±
JoeCP17 Nov 14, 2023
2ea2f70
refactor : 둜또 μ‹€ν–‰ Main ν•¨μˆ˜ λ‚΄, νŒŒλΌλ―Έν„° κ°’ μˆ˜μ •
JoeCP17 Nov 14, 2023
a4b41ce
refactor : Numbers 도메인 이름 λ³€κ²½κ³Ό 숫자 생성 λ©”μ„œλ“œ 이름 변경을 ν†΅ν•œ ν…ŒμŠ€νŠΈμ½”λ“œ μˆ˜μ •
JoeCP17 Nov 14, 2023
2c4f410
docs : μ „λž΅ 변경에 λ”°λ₯Έ λ¦¬λ“œλ―Έ λ‚΄ 도메인, 고렀사항 μˆ˜μ •
JoeCP17 Nov 14, 2023
20e6c26
test : 당첨 κ²°κ³Ό 확인 도메인 생성 , μ˜ˆμ™Έ, κ³„μ‚°κΈˆμ•‘ 쑰회, λ‹Ήμ²¨λ²ˆν˜Έ 쑰회 ν…ŒμŠ€νŠΈ 진행
JoeCP17 Nov 14, 2023
dc3f21d
refactor : 둜또 도메인 λ‚΄ 클래슀, λ‚΄λΆ€ λΉ„μ§€λ‹ˆμŠ€ 둜직 μˆ˜μ •
JoeCP17 Dec 2, 2023
027fca1
feat : Lotto Tickets 관리λ₯Ό μœ„ν•œ Lottos 일급 μ»¬λ ‰μ…˜ 생성
JoeCP17 Dec 2, 2023
5711a9e
refactor : 당첨 둜또 도메인 λ‚΄, ν”„λ‘œνΌν‹°, λ©”μ„œλ“œ μˆ˜μ •
JoeCP17 Dec 2, 2023
50fca4f
refactor : 둜또 당첨 κ²°κ³Ό 확인 둜직 μˆ˜μ • ( 도메인, dto 생성, main , output view )
JoeCP17 Dec 2, 2023
975f556
refactor : 둜또 ν‹°μΌ“ 도메인 μˆ˜μ •
JoeCP17 Dec 2, 2023
afc59b8
refactor : 둜또 상점 ( Lotto Store ) λ‚΄, λ³€κ²½λœ 도메인듀에 λ”°λ₯Έ 둜직 μˆ˜μ •
JoeCP17 Dec 2, 2023
1feb8b9
refactor : 번호 생성 Enum λ‚΄, 생성 둜직 μˆ˜μ •
JoeCP17 Dec 2, 2023
1de3c4e
refactor : λ³€κ²½λœ 도메인에 λ”°λ₯Έ, Lotto, Winning Lotto, Number Generator ν…ŒμŠ€νŠΈ μˆ˜μ •
JoeCP17 Dec 2, 2023
8e45867
test : 둜또 κ²°κ³Ό 도메인 λ‚΄ Dto λ³€ν™˜ ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 2, 2023
60d7112
test : 둜또 상점 λ‚΄ 둜또 λ°œκΈ‰ 및 결과확인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 2, 2023
1c01633
chore : Number 도메인 νŒ¨ν‚€μ§€ 이동 ( Lotto -> Number )
JoeCP17 Dec 4, 2023
d89078f
feat : λ³΄λ„ˆμŠ€ 숫자 도메인 μΆ”κ°€
JoeCP17 Dec 5, 2023
f4b3789
refactor : λ³΄λ„ˆμŠ€ 숫자 검증을 μœ„ν•œ Match Enum μˆ˜μ •
JoeCP17 Dec 5, 2023
bba6266
refactor : Lotto 도메인 λ‚΄, λ³΄λ„ˆμŠ€ 숫자 검증을 μœ„ν•œ count λ©”μ„œλ“œ μΆ”κ°€
JoeCP17 Dec 5, 2023
9cbdfd2
refactor : κ²°κ³Ό 둜또 도메인 λ‚΄ λ³΄λ„ˆμŠ€ 숫자 μΆ”κ°€
JoeCP17 Dec 5, 2023
6ea82ea
refactor : 둜또 상점 도메인 λ‚΄ μ–΄μƒ‰ν•œ λ³€μˆ˜λͺ… μˆ˜μ • 및 κ²°κ³Ό 검증 λ©”μ„œλ“œ μˆ˜μ •
JoeCP17 Dec 5, 2023
5cf19da
refactor : View 클래슀 object둜 μˆ˜μ • 및 λ³΄λ„ˆμŠ€λ³Ό Input λ©”μ„œλ“œμ™€ 수읡λ₯  print λ¬Έ μˆ˜μ •
JoeCP17 Dec 5, 2023
9855ccc
refactor : Main ν•¨μˆ˜ λ‚΄ λΉ„μ§€λ‹ˆμŠ€ 흐름별 λ©”μ„œλ“œ 뢄리 진행
JoeCP17 Dec 5, 2023
15da1fc
test : λ³΄λ„ˆμŠ€ 숫자 좔가에따λ₯Έ 각 도메인별 ν…ŒμŠ€νŠΈμ½”λ“œ μˆ˜μ • 및 재 ν…ŒμŠ€νŠΈ 진행
JoeCP17 Dec 5, 2023
07ea3e4
test : λ³΄λ„ˆμŠ€ 숫자 도메인 생성 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 5, 2023
4b72c0e
docs : Step3 λ¦¬λ“œλ―Έ μž‘μ„±
JoeCP17 Dec 5, 2023
89bd791
Merge branch 'step2' into main
JoeCP17 Dec 5, 2023
28c5bea
Merge branch 'step3' into main
JoeCP17 Dec 5, 2023
cdab130
chore : git revert
JoeCP17 Dec 6, 2023
409251d
chore : Number 도메인 νŒ¨ν‚€μ§€ 이동 ( Lotto -> Number )
JoeCP17 Dec 6, 2023
a3aed21
feat : λ³΄λ„ˆμŠ€ 숫자 도메인 μΆ”κ°€
JoeCP17 Dec 6, 2023
3f301a9
refactor : λ³΄λ„ˆμŠ€ 숫자 검증을 μœ„ν•œ Match Enum μˆ˜μ •
JoeCP17 Dec 6, 2023
09180db
refactor : Lotto 도메인 λ‚΄, λ³΄λ„ˆμŠ€ 숫자 검증을 μœ„ν•œ Count λ©”μ„œλ“œ μΆ”κ°€
JoeCP17 Dec 6, 2023
87f2a3d
refactor : κ²°κ³Ό 둜또 도메인 λ‚΄ λ³΄λ„ˆμŠ€ 숫자 μΆ”κ°€
JoeCP17 Dec 6, 2023
998da3a
refactor : 둜또 상점 도메인 λ‚΄ μ–΄μƒ‰ν•œ λ³€μˆ˜λͺ… μˆ˜μ • 및 κ²°κ³Ό 검증 λ©”μ„œλ“œ μˆ˜μ •
JoeCP17 Dec 6, 2023
ea8837a
refactor : View 클래슀 object둜 μˆ˜μ • 및 λ³΄λ„ˆμŠ€ λ³Ό input λ©”μ„œλ“œμ™€ 수읡λ₯  printλ¬Έ μˆ˜μ •
JoeCP17 Dec 6, 2023
d047c1c
refactor : Main ν•¨μˆ˜ λ‚΄ λΉ„μ§€λ‹ˆμŠ€ 흐름별 λ©”μ„œλ“œ 뢄리 진행
JoeCP17 Dec 6, 2023
6560e92
test : λ³΄λ„ˆμŠ€ 숫자 좔가에 λ”°λ₯Έ 각 도메인별 ν…ŒμŠ€νŠΈμ½”λ“œ μˆ˜μ • 및 재 ν…ŒμŠ€νŠΈ 진행
JoeCP17 Dec 6, 2023
8bd330f
test : λ³΄λ„ˆμŠ€ 숫자 도메인 생성 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 6, 2023
8a46177
docs : Step3 λ¦¬λ“œλ―Έ μž‘μ„±
JoeCP17 Dec 6, 2023
4496ebf
Merge branch 'joecp17' into step3
JoeCP17 Dec 6, 2023
c82ecd9
refactor : λ³΄λ„ˆμŠ€ 숫자 도메인 제거
JoeCP17 Dec 10, 2023
1e2fa7c
refactor : λ³΄λ„ˆμŠ€ 숫자 도메인 제거둜 μΈν•œ Number 둜 μˆ˜μ •
JoeCP17 Dec 10, 2023
680efc3
refactor : 당첨 둜또 도메인 λ‚΄, λ³΄λ„ˆμŠ€ λ„˜λ²„ μˆ˜μ • 및 쀑볡 체크 검증 μΆ”κ°€
JoeCP17 Dec 10, 2023
8efd234
test : 당첨 둜또 도메인 λ‚΄ 쀑볡 체크 μΆ”κ°€λ‘œ μΈν•œ ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 10, 2023
98a718c
refactor : 둜또 결과확인 둜직 μˆ˜μ •
JoeCP17 Dec 10, 2023
e81166d
test : 둜또 일급 μ»¬λ ‰μ…˜ 도메인 ( Lottos ) λ‚΄ 당첨 κ²°κ³Ό 확인 ν…ŒμŠ€νŠΈ μž‘μ„±
JoeCP17 Dec 10, 2023
2aaaf80
Merge branch 'step3'
JoeCP17 Dec 17, 2023
164ebed
refactor : Input / Output View λ‚΄, μˆ˜λ™ ꡬ맀 μΆ”κ°€
JoeCP17 Dec 26, 2023
1383fbf
feat : 둜또 쀑간결과 전달을 μœ„ν•œ Process Dto μΆ”κ°€
JoeCP17 Dec 26, 2023
4c17c65
style : Code Formatterλ₯Ό ν†΅ν•œ μŠ€νƒ€μΌ μˆ˜μ •
JoeCP17 Dec 26, 2023
d0aba47
feat : μˆ˜λ™ ν‹°μΌ“ ꡬ맀λ₯Ό μœ„ν•œ μˆ˜λ™ ν‹°μΌ“ μˆ˜λŸ‰ 도메인 생성
JoeCP17 Dec 26, 2023
b3d6657
refactor : ꡬ맀 μˆ˜λŸ‰ 도메인 λ‚΄, μˆ˜λ™ μˆ˜λŸ‰ μ œμ™Έ 둜직 μΆ”κ°€
JoeCP17 Dec 26, 2023
a294b27
refactor : InputView λ‚΄ 도메인 λ„€μž„ λ³€κ²½
JoeCP17 Dec 26, 2023
4c32c3f
refactor : λ‹Ήμ²¨λ²ˆν˜Έ, 둜또번호 쀑볡 검증 둜직 μˆ˜μ •
JoeCP17 Dec 26, 2023
8b19699
refactor : Lottos 도메인 λ‚΄, mutableListOf 둜직 μˆ˜μ •, μˆ˜λ™ 숫자 검증 둜직 μΆ”κ°€
JoeCP17 Dec 26, 2023
b154b18
refactor : 둜또 상점 λ‚΄, μˆ˜λ™ ꡬ맀 μš”κ΅¬μ‚¬ν•­μ— λ”°λ₯Έ 둜직 μˆ˜μ • 진행
JoeCP17 Dec 26, 2023
6d68d71
test : κ΅¬μž…κΈˆμ•‘, 둜또 개수λ₯Ό ν†΅ν•œ ꡬ맀 ν…ŒμŠ€νŠΈ 진행
JoeCP17 Dec 26, 2023
a9f8131
refactor : μˆ˜λ™ 둜또 ꡬ맀λ₯Ό μΆ”κ°€ν•œ main ν•¨μˆ˜ μˆ˜μ •
JoeCP17 Dec 26, 2023
2fa0905
feat : step4 둜또 μˆ˜λ™ ꡬ맀 readme μž‘μ„±
JoeCP17 Dec 26, 2023
d60d29d
Merge branch 'step4'
JoeCP17 Dec 26, 2023
534869e
Merge branch 'joecp17' into main
JoeCP17 Dec 26, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@
μΆ”κ°€ν•œ 도메인
- λ³΄λ„ˆμŠ€ 숫자 ( BonusNumber )

# Step4 - 둜또 μˆ˜λ™ ꡬ맀 ( Lotto )
좔가적인 μš”κ΅¬μ‚¬ν•­
- μ‚¬μš©μžκ°€ μˆ˜λ™μœΌλ‘œ μΆ”μ²¨λ²ˆν˜Έλ₯Ό μž…λ ₯ν•  수 μžˆλ„λ‘ ν•΄μ•Όν•œλ‹€.
- μž…λ ₯ν•œ κΈˆμ•‘, μžλ™ 생성 숫자, μˆ˜λ™ 생성 번호λ₯Ό μž…λ ₯ν•˜λ„λ‘ ν•΄μ•Όν•œλ‹€.
- μˆ˜λ™ 생성 λ²ˆν˜ΈλŠ” μžλ™ 생성 λ²ˆν˜Έμ™€ 쀑볡될 수 μ—†λ‹€.
- κ΅¬λ§€ν•œ κΈˆμ•‘μ—μ„œ μˆ˜λ™ μƒμ„±ν•œ 티켓을 μ œμ™Έν•œ λ‚˜λ¨Έμ§€κ°€ μƒμ„±λ˜μ–΄μ•Ό ν•œλ‹€.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ value class BuyAmount(

constructor(amount: Long) : this(BigDecimal.valueOf(amount))

fun divideByLotteryPrice(ticketPrice: Long): Int {
return amount.divide(BigDecimal.valueOf(ticketPrice)).toInt()
fun divideByLotteryPriceAndManualLottoAmount(ticketPrice: Long, manualTicketAmount: Int): Int {
val ticketAmount = amount.divide(BigDecimal.valueOf(ticketPrice)).toInt()
return ticketAmount - manualTicketAmount
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package camp.nextstep.edu.step.step2.domain.amount

@JvmInline
value class ManualTicketAmount(
val amount: Long
) {

init {
require(amount > 0) { "ꡬ맀 κΈˆμ•‘μ€ 0보닀 컀야 ν•©λ‹ˆλ‹€." }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Lotto(
return numbers.count { targetLotto.numbers.contains(it) }
}

fun isDuplicateNumber(anotherNumber: Number): Boolean {
return numbers.contains(anotherNumber)
}

fun countMatchBonus(bonusNumber: Number): Int {
return numbers.count { it.number == bonusNumber.number }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package camp.nextstep.edu.step.step2.domain.lotto

import camp.nextstep.edu.step.step2.domain.number.Number
import camp.nextstep.edu.step.step2.domain.result.LottoMatch
import java.util.stream.Collectors

Expand All @@ -11,16 +12,16 @@ class Lottos(
require(lottos.isNotEmpty()) { "λ‘œλ˜λŠ” 1개 이상이어야 ν•©λ‹ˆλ‹€." }
}

fun checkLottoNumbersByWinningLotto(winningLotto: WinningLotto): List<LottoMatch> {
val lottoMatchResults = mutableListOf<LottoMatch>()
fun isContainLottoNumbers(numbers: List<Number>): Boolean {
return lottos.contains(Lotto(numbers = numbers))
}

for (lotto in lottos) {
fun checkLottoNumbersByWinningLotto(winningLotto: WinningLotto): List<LottoMatch> {
return lottos.map { lotto ->
val matchNumbers = lotto.countMatch(winningLotto.winningLotto)
val matchBonus = lotto.countMatchBonus(winningLotto.bonusNumber)
lottoMatchResults.add(LottoMatch.of(matchNumbers, matchBonus))
LottoMatch.of(matchNumbers, matchBonus)
}
return lottoMatchResults
}

fun getLottoElements(): List<List<Int>> {
return lottos.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ data class WinningLotto(

init {
require(winningLotto.numbers.isNotEmpty()) { "λ‹Ήμ²¨λ²ˆν˜Έκ°€ μž…λ ₯λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€." }

// winningLotto λ‚΄ Numberλ“€κ³Ό bonusNumberκ°€ μ€‘λ³΅λ˜λŠ”μ§€ 검사
require(!winningLotto.numbers.contains(bonusNumber)) { "λ³΄λ„ˆμŠ€ λ²ˆν˜ΈλŠ” 당첨 λ²ˆν˜Έμ™€ 쀑볡될 수 μ—†μŠ΅λ‹ˆλ‹€." }
require(!winningLotto.isDuplicateNumber(bonusNumber)) { "λ³΄λ„ˆμŠ€ λ²ˆν˜ΈλŠ” 당첨 λ²ˆν˜Έμ™€ 쀑볡될 수 μ—†μŠ΅λ‹ˆλ‹€." }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ enum class LottoMatch(
SIX_MATCH(6, 0, 2_000_000_000),
FIVE_MATCH(5, 0, 1_500_000),
FIVE_MATCH_WITH_BONUS(5, 1, 30_000_000),
FOUR_MATCH(4, 0,50_000),
THREE_MATCH(3, 0,5_000),
NONE(0, 0,0);
FOUR_MATCH(4, 0, 50_000),
THREE_MATCH(3, 0, 5_000),
NONE(0, 0, 0);


companion object {
fun of(matchCount: Int, bonusMatch: Int): LottoMatch {
return values().find { it.matchCount == matchCount && it.bonusMatch == bonusMatch } ?: NONE
return values().find { it.matchCount == matchCount && it.bonusMatch == bonusMatch }
?: NONE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,31 @@ object LottoStore {
/**
* @description : κ΅¬λ§€κΈˆμ•‘μ— λ”°λ₯Έ 둜또 ν‹°μΌ“ μˆ˜λŸ‰μ„ κ΅¬ν•œλ‹€.
*/
fun buyLottoTickets(buyAmount: BuyAmount): LottoTicketAmount {
val lottoTicketAmount = buyAmount.divideByLotteryPrice(ticketPrice = LOTTO_TICKET_PRICE)
fun buyAutoLottoTickets(buyAmount: BuyAmount, manualTicketAmount: Int): LottoTicketAmount {
val lottoTicketAmount = buyAmount.divideByLotteryPriceAndManualLottoAmount(
ticketPrice = LOTTO_TICKET_PRICE,
manualTicketAmount = manualTicketAmount
)

return LottoTicketAmount(lottoTicketAmount)
}

/**
* @description : 둜또 ν‹°μΌ“ μˆ˜λŸ‰μ— λ”°λ₯Έ 둜또 번호λ₯Ό μƒμ„±ν•œλ‹€.
*/
fun createNumbersByLottoTicketAmount(ticketAmount: LottoTicketAmount): Lottos {
fun createNumbersByLottoTicketAmount(
ticketAmount: LottoTicketAmount,
manualLottos: Lottos
): Lottos {
val lottoTickets = mutableListOf<Lotto>()

for (i in 1..ticketAmount.lottoTicketAmount) {
val numbers = NumberGenerator.generate(NumberGenerator.LOTTO_RANDOM, START_NUMBER, END_NUMBER)
lottoTickets.add(Lotto(numbers = numbers))
val numbers =
NumberGenerator.generate(NumberGenerator.LOTTO_RANDOM, START_NUMBER, END_NUMBER)

if (!manualLottos.isContainLottoNumbers(numbers)) {
lottoTickets.add(Lotto(numbers = numbers))
}
}

return Lottos(lottos = lottoTickets)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package camp.nextstep.edu.step.step2.dto

data class LottoProcessDto(
val manualTicketAmount: Int,
val autoTicketAmount: Int,
val lottoTicketList: List<List<Int>>,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package camp.nextstep.edu.step.step2.dto

data class LottoResultDto (
data class LottoResultDto(
val matchResponse: List<MatchResponse>,
val lottoProfitRate: Double
) {
) {

data class MatchResponse(
val matchCount: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import camp.nextstep.edu.step.step2.domain.number.Number
enum class NumberGenerator(
val generate: (Int, Int) -> List<Int>
) {
LOTTO_RANDOM({ startNum, endNum -> (startNum..endNum).shuffled().subList(0, 6).distinct().sorted() });
LOTTO_RANDOM({ startNum, endNum ->
(startNum..endNum).shuffled().subList(0, 6).distinct().sorted()
});


companion object {
fun generate(generator: NumberGenerator, startNumber: Int, endNumber: Int): List<Number> {
return generator.generate(startNumber, endNumber).map { Number(it) }
return generator.generate(startNumber, endNumber).map { Number(it) }
}
}

Expand Down
28 changes: 20 additions & 8 deletions src/main/kotlin/camp/nextstep/edu/step/step2/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@ import camp.nextstep.edu.step.step2.domain.amount.BuyAmount
import camp.nextstep.edu.step.step2.domain.lotto.Lottos
import camp.nextstep.edu.step.step2.domain.lotto.WinningLotto
import camp.nextstep.edu.step.step2.domain.store.LottoStore
import camp.nextstep.edu.step.step2.dto.LottoProcessDto
import camp.nextstep.edu.step.step2.view.InputView
import camp.nextstep.edu.step.step2.view.OutputView


fun main() {
val buyAmount = InputView.getInputValueAndReturnBuyAmount()
val manualLottoCount = InputView.inputManualLottoCount()
val manualLottos = InputView.inputManalLottoNumbers(ticketAmount = manualLottoCount.amount)

val lottos = buyLottoTicketsWithAmount(buyAmount = buyAmount)
val lottos = buyLottoTicketsWithAmount(buyAmount = buyAmount, manualLottos = manualLottos)

checkLottoTicketsWinningResult(lottos = lottos)
}

private fun buyLottoTicketsWithAmount(buyAmount: BuyAmount): Lottos {
val tickets = LottoStore.buyLottoTickets(buyAmount = buyAmount)

val lottos = LottoStore.createNumbersByLottoTicketAmount(ticketAmount = tickets)
private fun buyLottoTicketsWithAmount(buyAmount: BuyAmount, manualLottos: Lottos): Lottos {
val tickets = LottoStore.buyAutoLottoTickets(
buyAmount = buyAmount,
manualTicketAmount = manualLottos.getLottoSize()
)
val lottos = LottoStore.createNumbersByLottoTicketAmount(
ticketAmount = tickets,
manualLottos = manualLottos
)

val ticketElements = lottos.getLottoElements()
val autoLottoNumbers = lottos.getLottoElements()
val manualLottoNumbers = manualLottos.getLottoElements()

OutputView.displayTicketsNumbers(
ticketsAmount = tickets.lottoTicketAmount,
ticketNumbers = ticketElements
LottoProcessDto(
manualTicketAmount = manualLottos.getLottoSize(),
autoTicketAmount = tickets.lottoTicketAmount,
lottoTicketList = manualLottoNumbers + autoLottoNumbers
)
)

return lottos
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/camp/nextstep/edu/step/step2/view/InputView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package camp.nextstep.edu.step.step2.view

import camp.nextstep.edu.step.step2.domain.amount.BuyAmount
import camp.nextstep.edu.step.step2.domain.amount.ManualTicketAmount
import camp.nextstep.edu.step.step2.domain.lotto.Lotto
import camp.nextstep.edu.step.step2.domain.lotto.Lottos
import camp.nextstep.edu.step.step2.domain.number.Number

object InputView {
Expand All @@ -11,6 +13,17 @@ object InputView {
return BuyAmount(readLine()!!.toLong())
}

fun inputManualLottoCount(): ManualTicketAmount {
println("μˆ˜λ™μœΌλ‘œ ꡬ맀할 둜또 수λ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”.")
return ManualTicketAmount(amount = readLine()!!.toLong())
}

fun inputManalLottoNumbers(ticketAmount: Long): Lottos {
println("μˆ˜λ™μœΌλ‘œ ꡬ맀할 번호λ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”.")
val lottoList = (1..ticketAmount).map { Lotto.ofInputValues(numbers = readLine()!!) }
return Lottos(lottos = lottoList)
}

fun inputLastWeekWinningNumbers(): Lotto {
println("μ§€λ‚œ μ£Ό 당첨 번호λ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”.")
return Lotto.ofInputValues(numbers = readLine()!!)
Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/camp/nextstep/edu/step/step2/view/OutputView.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package camp.nextstep.edu.step.step2.view

import camp.nextstep.edu.step.step2.dto.LottoProcessDto
import camp.nextstep.edu.step.step2.dto.LottoResultDto

object OutputView {

fun displayTicketsNumbers(ticketsAmount: Int, ticketNumbers: List<List<Int>>) {
println("${ticketsAmount}개λ₯Ό κ΅¬λ§€ν–ˆμŠ΅λ‹ˆλ‹€.")
fun displayTicketsNumbers(lottoProcessDto: LottoProcessDto) {
println("μˆ˜λ™μœΌλ‘œ ${lottoProcessDto.manualTicketAmount}μž₯, μžλ™μœΌλ‘œ ${lottoProcessDto.autoTicketAmount}개λ₯Ό κ΅¬λ§€ν–ˆμŠ΅λ‹ˆλ‹€.")

for (ticketNumber in ticketNumbers) {
println(ticketNumber)
for (lottoTicket in lottoProcessDto.lottoTicketList) {
println(lottoTicket)
}

}

fun displayLottoResultByDto(lottoResultDto: LottoResultDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import java.math.BigDecimal
@DisplayName("둜또 상점은")
class LottoStoreTest : BehaviorSpec({

Given("κ΅¬μž… κΈˆμ•‘μ΄ 주어지고") {
Given("κ΅¬μž… κΈˆμ•‘κ³Ό μˆ˜λ™ 둜또 κ°œμˆ˜κ°€ 주어지고") {
val buyAmount = BuyAmount(amount = BigDecimal.valueOf(10000L))
val manualTicketAmount = 2

When("둜또λ₯Ό κ΅¬λ§€ν•˜λ©΄") {
val lottoTickets = LottoStore.buyLottoTickets(buyAmount)
val lottoTickets = LottoStore.buyAutoLottoTickets(buyAmount, manualTicketAmount)

Then("κ΅¬λ§€ν•œ κΈˆμ•‘λ§ŒνΌμ˜ 둜또 ν‹°μΌ“ 수λ₯Ό λ°˜ν™˜ν•œλ‹€.") {
lottoTickets.lottoTicketAmount shouldBe 10
lottoTickets.lottoTicketAmount shouldBe 8
}
}
}
Expand Down Expand Up @@ -82,12 +83,24 @@ class LottoStoreTest : BehaviorSpec({
}
}

Given("둜또의 μˆ˜λŸ‰μ΄μ£Όμ–΄μ§€κ³ ") {
Given("둜또의 μˆ˜λŸ‰κ³Ό μˆ˜λ™ λ‘œλ˜λ²ˆν˜Έκ°€ 주어지고") {
val lottoTicketAmount = LottoTicketAmount(lottoTicketAmount = 10)
val manualLotto = Lottos( lottos = listOf(
Lotto(
listOf(
Number(number = 1),
Number(number = 2),
Number(number = 3),
Number(number = 4),
Number(number = 5),
Number(number = 6)
)
)
))

When("둜또 λ°œκΈ‰μ„ μ‹œλ„ν•˜λ©΄") {
val lottoTickets =
LottoStore.createNumbersByLottoTicketAmount(ticketAmount = lottoTicketAmount)
LottoStore.createNumbersByLottoTicketAmount(ticketAmount = lottoTicketAmount, manualLottos = manualLotto)

Then("κ΅¬λ§€ν•œ μˆ˜λŸ‰λ§ŒνΌμ˜ λ‘œλ˜κ°€ λ°œκΈ‰λœλ‹€.") {
lottoTickets.lottos.size shouldBe 10
Expand Down Expand Up @@ -148,5 +161,4 @@ class LottoStoreTest : BehaviorSpec({
}
}
}

})