diff --git a/docs/README.md b/docs/README.md index e69de29bb2..6bd2254f30 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,21 @@ +##구현 할 기능 정리 +0.Application + (1) view에서 시작 문구를 호출 + (2) 입력값을 받아 controller로 전달 + (3) view에서 끝난 문구를 호출 +1.model + (1) 사용자의 입력값을 저장하는 모델 + (2) 1~9의 랜덤수 중 임의의 수 3개를 선택하여 저장하는 모델 +2.controller + (1) view의 상태를 application에 전달 + (2) 사용자의 입력값을 모델에 저장 + (3) 사용자가 올바른 입력값을 넣으면 service로 입력값을 전달하고 + (4) 게임이 끝난 경우 재시작/종료를 구분하는 기능 +3.service + (1) 같은 수가 같은 자리에 있는지, 다른 자리에 있는지, 같은 수가 없는지 확인하는 기능 + (2) 올바른 입력값을 넣었는지 확인하는 기능 +4.view + (1) 입력한 숫자에 따른 결과 화면 띄우기 + (2) 잘못된 값을 넣은 경우 -> IllegalArgumentException 띄우기 + (3) 모든 숫자를 맞춰 종료하는 화면, 재시작과 게임종료를 알림 + (4) 게임 시작 문구 출력 "숫자 야구 게임을 시작합니다" diff --git a/hs_err_pid23272.log b/hs_err_pid23272.log new file mode 100644 index 0000000000..ceb77e8b0b --- /dev/null +++ b/hs_err_pid23272.log @@ -0,0 +1,262 @@ +# +# There is insufficient memory for the Java Runtime Environment to continue. +# Native memory allocation (mmap) failed to map 398458880 bytes. Error detail: G1 virtual space +# Possible reasons: +# The system is out of physical RAM or swap space +# This process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap +# Possible solutions: +# Reduce memory load on the system +# Increase physical memory or swap space +# Check if swap backing store is full +# Decrease Java heap size (-Xmx/-Xms) +# Decrease number of Java threads +# Decrease Java thread stack sizes (-Xss) +# Set larger code cache with -XX:ReservedCodeCacheSize= +# JVM is running with Unscaled Compressed Oops mode in which the Java heap is +# placed in the first 4GB address space. The Java Heap base address is the +# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress +# to set the Java Heap base and to place the Java Heap above 4GB virtual address. +# This output file may be truncated or incomplete. +# +# Out of Memory Error (os_windows.cpp:3613), pid=23272, tid=3492 +# +# JRE version: (17.0.12+7) (build ) +# Java VM: OpenJDK 64-Bit Server VM (17.0.12+7-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) +# No core dump will be written. Minidumps are not enabled by default on client versions of Windows +# + +--------------- S U M M A R Y ------------ + +Command Line: -Dorg.gradle.internal.worker.tmpdir=C:\Users\User\java-baseball-6\build\tmp\test\work -Dorg.gradle.native=false -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:54325 -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=KR -Duser.language=ko -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 1' + +Host: 13th Gen Intel(R) Core(TM) i5-13500H, 16 cores, 23G, Windows 11 , 64 bit Build 22621 (10.0.22621.3958) +Time: Tue Oct 22 17:55:48 2024 Windows 11 , 64 bit Build 22621 (10.0.22621.3958) elapsed time: 0.017812 seconds (0d 0h 0m 0s) + +--------------- T H R E A D --------------- + +Current thread (0x00000251e82f7600): JavaThread "Unknown thread" [_thread_in_vm, id=3492, stack(0x00000071abb00000,0x00000071abc00000)] + +Stack: [0x00000071abb00000,0x00000071abc00000] +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x67f4f9] +V [jvm.dll+0x836eaa] +V [jvm.dll+0x83896e] +V [jvm.dll+0x838fd3] +V [jvm.dll+0x247f6f] +V [jvm.dll+0x67c2b9] +V [jvm.dll+0x670d7a] +V [jvm.dll+0x307b5b] +V [jvm.dll+0x30f046] +V [jvm.dll+0x35f22e] +V [jvm.dll+0x35f46f] +V [jvm.dll+0x2deb7c] +V [jvm.dll+0x2dfad4] +V [jvm.dll+0x80870b] +V [jvm.dll+0x36cfa1] +V [jvm.dll+0x7e70f5] +V [jvm.dll+0x3f0adf] +V [jvm.dll+0x3f2631] +C [jli.dll+0x528f] +C [ucrtbase.dll+0x29333] +C [KERNEL32.DLL+0x1257d] +C [ntdll.dll+0x5af08] + + +--------------- P R O C E S S --------------- + +Threads class SMR info: +_java_thread_list=0x00007ffe2ba06f18, length=0, elements={ +} + +Java Threads: ( => current thread ) + +Other Threads: + 0x00000251e8327c90 GCTaskThread "GC Thread#0" [stack: 0x00000071abc00000,0x00000071abd00000] [id=10616] + 0x00000251e832cbe0 ConcurrentGCThread "G1 Main Marker" [stack: 0x00000071abd00000,0x00000071abe00000] [id=11324] + 0x00000251e832d600 ConcurrentGCThread "G1 Conc#0" [stack: 0x00000071abe00000,0x00000071abf00000] [id=29372] + +[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffe2b1bf277] + +VM state: not at safepoint (not fully initialized) + +VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) +[0x00000251e82f3c70] Heap_lock - owner thread: 0x00000251e82f7600 + +Heap address: 0x00000000e0000000, size: 512 MB, Compressed Oops mode: 32-bit + +CDS archive(s) mapped at: [0x0000000000000000-0x0000000000000000-0x0000000000000000), size 0, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 1. +Narrow klass base: 0x0000000000000000, Narrow klass shift: 0, Narrow klass range: 0x0 + +GC Precious Log: + + +Heap: + garbage-first heap total 0K, used 0K [0x00000000e0000000, 0x0000000100000000) + region size 1024K, 0 young (0K), 0 survivors (0K) + +[error occurred during error reporting (printing heap information), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffe2b5a8829] + +GC Heap History (0 events): +No events + +Dll operation events (1 events): +Event: 0.007 Loaded shared library C:\Users\User\.jdks\corretto-17.0.12\bin\java.dll + +Deoptimization events (0 events): +No events + +Classes loaded (0 events): +No events + +Classes unloaded (0 events): +No events + +Classes redefined (0 events): +No events + +Internal exceptions (0 events): +No events + +VM Operations (0 events): +No events + +Events (0 events): +No events + + +Dynamic libraries: +0x00007ff7b22d0000 - 0x00007ff7b22de000 C:\Users\User\.jdks\corretto-17.0.12\bin\java.exe +0x00007ffe83e30000 - 0x00007ffe84047000 C:\Windows\SYSTEM32\ntdll.dll +0x00007ffe82d50000 - 0x00007ffe82e14000 C:\Windows\System32\KERNEL32.DLL +0x00007ffe81140000 - 0x00007ffe814f7000 C:\Windows\System32\KERNELBASE.dll +0x00007ffe81790000 - 0x00007ffe818a1000 C:\Windows\System32\ucrtbase.dll +0x00007ffe77e60000 - 0x00007ffe77e77000 C:\Users\User\.jdks\corretto-17.0.12\bin\jli.dll +0x00007ffe77e80000 - 0x00007ffe77e9b000 C:\Users\User\.jdks\corretto-17.0.12\bin\VCRUNTIME140.dll +0x00007ffe838f0000 - 0x00007ffe83a9f000 C:\Windows\System32\USER32.dll +0x00007ffe816e0000 - 0x00007ffe81706000 C:\Windows\System32\win32u.dll +0x00007ffe81e80000 - 0x00007ffe81ea9000 C:\Windows\System32\GDI32.dll +0x00007ffe81970000 - 0x00007ffe81a88000 C:\Windows\System32\gdi32full.dll +0x00007ffe81ac0000 - 0x00007ffe81b5a000 C:\Windows\System32\msvcp_win.dll +0x00007ffe68230000 - 0x00007ffe684c3000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.3672_none_2713b9d173822955\COMCTL32.dll +0x00007ffe81b60000 - 0x00007ffe81c07000 C:\Windows\System32\msvcrt.dll +0x00007ffe83600000 - 0x00007ffe83631000 C:\Windows\System32\IMM32.DLL +0x00007ffe78990000 - 0x00007ffe7899c000 C:\Users\User\.jdks\corretto-17.0.12\bin\vcruntime140_1.dll +0x00007ffe596b0000 - 0x00007ffe5973d000 C:\Users\User\.jdks\corretto-17.0.12\bin\msvcp140.dll +0x00007ffe2aed0000 - 0x00007ffe2bb3a000 C:\Users\User\.jdks\corretto-17.0.12\bin\server\jvm.dll +0x00007ffe83820000 - 0x00007ffe838d2000 C:\Windows\System32\ADVAPI32.dll +0x00007ffe83b80000 - 0x00007ffe83c28000 C:\Windows\System32\sechost.dll +0x00007ffe81a90000 - 0x00007ffe81ab8000 C:\Windows\System32\bcrypt.dll +0x00007ffe82e20000 - 0x00007ffe82f34000 C:\Windows\System32\RPCRT4.dll +0x00007ffe837a0000 - 0x00007ffe83811000 C:\Windows\System32\WS2_32.dll +0x00007ffe7fff0000 - 0x00007ffe8003d000 C:\Windows\SYSTEM32\POWRPROF.dll +0x00007ffe77ec0000 - 0x00007ffe77ef4000 C:\Windows\SYSTEM32\WINMM.dll +0x00007ffe69470000 - 0x00007ffe6947a000 C:\Windows\SYSTEM32\VERSION.dll +0x00007ffe7ffd0000 - 0x00007ffe7ffe3000 C:\Windows\SYSTEM32\UMPDC.dll +0x00007ffe80280000 - 0x00007ffe80298000 C:\Windows\SYSTEM32\kernel.appcore.dll +0x00007ffe78930000 - 0x00007ffe7893a000 C:\Users\User\.jdks\corretto-17.0.12\bin\jimage.dll +0x00007ffe7eaa0000 - 0x00007ffe7ecd2000 C:\Windows\SYSTEM32\DBGHELP.DLL +0x00007ffe820b0000 - 0x00007ffe8243e000 C:\Windows\System32\combase.dll +0x00007ffe83aa0000 - 0x00007ffe83b77000 C:\Windows\System32\OLEAUT32.dll +0x00007ffe583f0000 - 0x00007ffe58422000 C:\Windows\SYSTEM32\dbgcore.DLL +0x00007ffe81710000 - 0x00007ffe8178b000 C:\Windows\System32\bcryptPrimitives.dll +0x00007ffe62410000 - 0x00007ffe6244b000 C:\Users\User\.jdks\corretto-17.0.12\bin\jdwp.dll +0x00007ffe66ee0000 - 0x00007ffe66f05000 C:\Users\User\.jdks\corretto-17.0.12\bin\java.dll + +dbghelp: loaded successfully - version: 4.0.5 - missing functions: none +symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Users\User\.jdks\corretto-17.0.12\bin;C:\Windows\SYSTEM32;C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.3672_none_2713b9d173822955;C:\Users\User\.jdks\corretto-17.0.12\bin\server + +VM Arguments: +jvm_args: -Dorg.gradle.internal.worker.tmpdir=C:\Users\User\java-baseball-6\build\tmp\test\work -Dorg.gradle.native=false -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:54325 -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=KR -Duser.language=ko -Duser.variant -ea +java_command: worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 1' +java_class_path (initial): C:\\Users\\User\\.gradle\\caches\\8.1.1\\workerMain\\gradle-worker.jar;C:\\Users\\User\\java-baseball-6\\build\\classes\\java\\test;C:\\Users\\User\\java-baseball-6\\build\\classes\\java\\main;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\com.github.woowacourse-projects\\mission-utils\\1.1.0\\a4b1a3600a51a05d44913c93181de7d143fadce2\\mission-utils-1.1.0.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.assertj\\assertj-core\\3.21.0\\27a14d6d22c4e3d58f799fb2a5ca8eaf53e6942a\\assertj-core-3.21.0.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter-params\\5.8.1\\13afdb5d414cbe991fce3ef6b864de77c9644dae\\junit-jupiter-params-5.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter-engine\\5.8.1\\21b86e08aae2720bbf017703669948be96d1388c\\junit-jupiter-engine-5.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter-api\\5.8.1\\6538b88eb8bf8811bc7b6efb5246f835c15e0bfe\\junit-jupiter-api-5.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.platform\\junit-platform-engine\\1.8.1\\e6c63bf990dc88a6527b4ed617b23e47048f07e0\\junit-platform-engine-1.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.platform\\junit-platform-commons\\1.8.1\\1e362cbe6d0f225b066757865e233972557484\\junit-platform-commons-1.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter\\5.8.1\\73a218cf02d36d4e87bb9697fdbe0780e92b6bd3\\junit-jupiter-5.8.1.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.mockito\\mockito-inline\\3.12.4\\3d1dffee9a8a1998ec782383ca2f818848f2d5f1\\mockito-inline-3.12.4.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.mockito\\mockito-core\\3.12.4\\f9cdc14ea4a3573c0c0366d47d5ca960be24ddb6\\mockito-core-3.12.4.jar;C:\\Users\\User\\.gradle\\caches\\modules-2\\files-2.1\\org.opentest4j\\opente +Launcher Type: SUN_STANDARD + +[Global flags] + intx CICompilerCount = 12 {product} {ergonomic} + uint ConcGCThreads = 3 {product} {ergonomic} + uint G1ConcRefinementThreads = 13 {product} {ergonomic} + size_t G1HeapRegionSize = 1048576 {product} {ergonomic} + uintx GCDrainStackTargetSize = 64 {product} {ergonomic} + size_t InitialHeapSize = 398458880 {product} {ergonomic} + size_t MarkStackSize = 4194304 {product} {ergonomic} + size_t MaxHeapSize = 536870912 {product} {command line} + size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} + size_t MinHeapSize = 8388608 {product} {ergonomic} + uintx NonNMethodCodeHeapSize = 7602480 {pd product} {ergonomic} + uintx NonProfiledCodeHeapSize = 122027880 {pd product} {ergonomic} + uintx ProfiledCodeHeapSize = 122027880 {pd product} {ergonomic} + uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} + bool SegmentedCodeCache = true {product} {ergonomic} + size_t SoftMaxHeapSize = 536870912 {manageable} {ergonomic} + bool UseCompressedClassPointers = true {product lp64_product} {ergonomic} + bool UseCompressedOops = true {product lp64_product} {ergonomic} + bool UseG1GC = true {product} {ergonomic} + bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} + +Logging: +Log output configuration: + #0: stdout all=warning uptime,level,tags + #1: stderr all=off uptime,level,tags + +Environment Variables: +JAVA_HOME=C:\Program Files\Java\jdk-21 +PATH=C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Java\jdk-21\bin;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\flutter\bin;C:\Program Files\JetBrains\PyCharm 2023.2.3\bin;;C:\Users\User\.dotnet\tools;C:\Firebase_cli;C:\Users\User\AppData\Local\Pub\Cache\bin;C:\Users\User\AppData\Roaming\npm;C:\Users\User\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\User\AppData\Local\JetBrains\IntelliJ IDEA 2024.2.1\bin;;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.1\bin; +USERNAME=User +OS=Windows_NT +PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 186 Stepping 2, GenuineIntel +TMP=C:\Users\User\AppData\Local\Temp +TEMP=C:\Users\User\AppData\Local\Temp + + + +Periodic native trim disabled + + +--------------- S Y S T E M --------------- + +OS: + Windows 11 , 64 bit Build 22621 (10.0.22621.3958) +OS uptime: 4 days 14:55 hours + +CPU: total 16 (initial active 16) (8 cores per cpu, 2 threads per core) family 6 model 186 stepping 2 microcode 0x410e, cx8, cmov, fxsr, ht, mmx, 3dnowpref, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, lzcnt, tsc, tscinvbit, avx, avx2, aes, erms, clmul, bmi1, bmi2, adx, sha, fma, vzeroupper, clflush, clflushopt, clwb +Processor Information for processor 0 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 1 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 2 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 3 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 4 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 5 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 6 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 7 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 8 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 9 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 10 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 11 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 12 + Max Mhz: 2600, Current Mhz: 1505, Mhz Limit: 2600 +Processor Information for processor 13 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 14 + Max Mhz: 2600, Current Mhz: 2600, Mhz Limit: 2600 +Processor Information for processor 15 + Max Mhz: 2600, Current Mhz: 1505, Mhz Limit: 2600 + +Memory: 4k page, system-wide physical 24208M (4186M free) +TotalPageFile size 97936M (AvailPageFile size 91M) +current process WorkingSet (physical memory assigned to process): 12M, peak: 12M +current process commit charge ("private bytes"): 70M, peak: 450M + +vm_info: OpenJDK 64-Bit Server VM (17.0.12+7-LTS) for windows-amd64 JRE (17.0.12+7-LTS), built on Jul 10 2024 20:46:33 by "Administrator" with MS VC++ 16.10 / 16.11 (VS2019) + +END. diff --git a/src/main/java/baseball/Application.java b/src/main/java/baseball/Application.java index dd95a34214..e8413dc97e 100644 --- a/src/main/java/baseball/Application.java +++ b/src/main/java/baseball/Application.java @@ -1,7 +1,14 @@ package baseball; +import baseball.controller.UserViewController; +import camp.nextstep.edu.missionutils.Console; + public class Application { public static void main(String[] args) { // TODO: 프로그램 구현 + UserViewController userViewController = new UserViewController(); + userViewController.start(); + String str = Console.readLine(); + userViewController.userInput(str); } } diff --git a/src/main/java/baseball/controller/UserViewController.java b/src/main/java/baseball/controller/UserViewController.java new file mode 100644 index 0000000000..1d4765658a --- /dev/null +++ b/src/main/java/baseball/controller/UserViewController.java @@ -0,0 +1,70 @@ +package baseball.controller; + +import baseball.model.RandomPickData; +import baseball.model.UserInputData; +import baseball.service.InputValidService; +import baseball.service.Service; +import baseball.view.UserViewResponse; +import camp.nextstep.edu.missionutils.Console; + +import java.util.List; + +import static baseball.view.UserViewResponse.*; + +public class UserViewController { + UserInputData userInputData; + InputValidService inputValidService = new InputValidService(); + Service service = new Service(); + static RandomPickData randomPickData; + + //(1) view의 상태를 application에 전달 + public void start(){ + START_GAME_MESSAGE(); + } + + //(2) 사용자의 입력값을 모델에 저장 + public void userInput(String str){ + randomPickData = new RandomPickData(); + userInputData = new UserInputData(); + userInputData.setStr(str); + + //입력값의 유효성 판단 + while(inputValidService.isStrikeAll()){ + String input = getInput(); + if(inputValidService.isInputValid(input)){ + String res = service.judgement(input, getRandomPicks()); + JUDGEMENT_MESSAGE(res); + }else{ + EXCEPTION_MESSAGE(); break; + } + if(inputValidService.isStrikeAll()){ + continueOrEndGame(); + break; + } + userInputData.setStr(Console.readLine()); + } + } + + private void continueOrEndGame(){ + END_GAME_MESSAGE(); + String ctn = Console.readLine(); + if(inputValidService.isInputValid(ctn)){ + if(inputValidService.continueOrEndGame(ctn)){ + String newInput = Console.readLine(); + userInput(newInput); + }else{ + System.out.println(); + } + }else{ + EXCEPTION_MESSAGE(); + } + } + + public String getInput(){ + return userInputData.getStr(); + } + + public List getRandomPicks(){ + return randomPickData.getRandomList(); + } +} diff --git a/src/main/java/baseball/model/RandomPickData.java b/src/main/java/baseball/model/RandomPickData.java new file mode 100644 index 0000000000..e29100561e --- /dev/null +++ b/src/main/java/baseball/model/RandomPickData.java @@ -0,0 +1,32 @@ +package baseball.model; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.ArrayList; +import java.util.List; + +public class RandomPickData { + private List randomList = new ArrayList<>(); + + public RandomPickData(){ + randomPick(); + } + + private void randomPick(){ + String random = ""; + for(int i=0; i<3; i++){ + while(true){ + random = String.valueOf(Randoms.pickNumberInRange(1,9)); + if(!randomList.contains(random)){ + break; + } + } + this.randomList.add(random); + } + + } + + public List getRandomList(){ + return randomList; + } +} diff --git a/src/main/java/baseball/model/UserInputData.java b/src/main/java/baseball/model/UserInputData.java new file mode 100644 index 0000000000..65f5c9ed2a --- /dev/null +++ b/src/main/java/baseball/model/UserInputData.java @@ -0,0 +1,13 @@ +package baseball.model; + +public class UserInputData { + private String str; + public UserInputData(){} + + public void setStr(String str){ + this.str = str; + } + public String getStr(){ + return this.str; + } +} diff --git a/src/main/java/baseball/service/InputValidService.java b/src/main/java/baseball/service/InputValidService.java new file mode 100644 index 0000000000..e7aadace60 --- /dev/null +++ b/src/main/java/baseball/service/InputValidService.java @@ -0,0 +1,43 @@ +package baseball.service; + +public class InputValidService { + boolean endGame = false; + //올바른 입력값이 들어왔는지 확인 + public boolean isInputValid(String str){ + //게임이 안끝났을 경우 + if(!endGame){ + for(int i=0; i 57){ + return false; + } + } + return true; + } + + if(str.charAt(0) == 49 || str.charAt(0) == 50){ + return true; + } + return false; + } + + public void updateStatus(){ + this.endGame = !endGame; + } + + public boolean continueOrEndGame(String ctn){ + int answer = Integer.parseInt(ctn); + switch(answer){ + case 1: + updateStatus(); + return true; + case 2: + return false; + } + return false; + } + + public boolean isStrikeAll(){ + return endGame; + } +} diff --git a/src/main/java/baseball/service/Service.java b/src/main/java/baseball/service/Service.java new file mode 100644 index 0000000000..7d39de3782 --- /dev/null +++ b/src/main/java/baseball/service/Service.java @@ -0,0 +1,49 @@ +package baseball.service; + +import java.util.List; + +public class Service { + InputValidService inputValidService = new + InputValidService(); + + public String judgement(String str, List ls){ + int strike = 0; + int ball = 0; + for(int i=0; i<3; i++){ + String target = str.substring(i,i+1); + for(String collect : ls){ + if(target.equals(collect)){ + if(ls.indexOf(collect) == i){ + strike +=1; + } + else{ + ball +=1; + } + } + } + } + String res = result(strike, ball); + if(strike == 3){ + strikeAll(); + } + return res; + } + + private String result(int strike, int ball){ + String res = "낫싱"; + if(strike > 0){ + res = String.valueOf(strike)+"스트라이크 "; + } + else if(ball > 0){ + res += String.valueOf(ball)+"볼 "; + return res; + } + return res; + } + + private void strikeAll(){ + inputValidService.updateStatus(); + } + + +} diff --git a/src/main/java/baseball/view/UserViewResponse.java b/src/main/java/baseball/view/UserViewResponse.java new file mode 100644 index 0000000000..2a843a6b18 --- /dev/null +++ b/src/main/java/baseball/view/UserViewResponse.java @@ -0,0 +1,27 @@ +package baseball.view; + +public class UserViewResponse { + + //(1) 입력한 숫자에 따른 결과 화면 띄우기 + static final public void JUDGEMENT_MESSAGE(String res){ + System.out.println(res); + } + + //(2) 잘못된 값을 넣은 경우 -> IllegalArgumentException 띄우기 + static final public void EXCEPTION_MESSAGE(){ + IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); + throw illegalArgumentException; + } + + //(3) 모든 숫자를 맞춰 종료하는 화면, 재시작과 게임종료를 알림 + static final public void END_GAME_MESSAGE(){ + System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); + System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); + } + + //(4) 게임 시작 문구 출력 "숫자 야구 게임을 시작합니다" + static final public void START_GAME_MESSAGE(){ + System.out.print("숫자 야구 게임을 시작합니다."); + } + +} diff --git a/src/test/java/baseball/controller/UserViewControllerTest.java b/src/test/java/baseball/controller/UserViewControllerTest.java new file mode 100644 index 0000000000..716155cfa3 --- /dev/null +++ b/src/test/java/baseball/controller/UserViewControllerTest.java @@ -0,0 +1,22 @@ +package baseball.controller; + +import baseball.model.RandomPickData; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class UserViewControllerTest { + RandomPickData randomPickData; + @Test + void userInputTest(){ + //given + String str = "123"; + randomPickData = new RandomPickData(); + List ls = randomPickData.getRandomList(); + //when + //then + } + +} \ No newline at end of file diff --git a/src/test/java/baseball/model/RandomPickDataTest.java b/src/test/java/baseball/model/RandomPickDataTest.java new file mode 100644 index 0000000000..33866b51c4 --- /dev/null +++ b/src/test/java/baseball/model/RandomPickDataTest.java @@ -0,0 +1,30 @@ +package baseball.model; + +import camp.nextstep.edu.missionutils.Randoms; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class RandomPickDataTest { + @Test + void test1(){ + List randomList = new ArrayList<>(); + String res = ""; + for(int i=0; i<3; i++){ + while(true){ + int random = Randoms.pickNumberInRange(1,9); + if(!randomList.contains(random)){ + res = String.valueOf(random); + break; + } + } + randomList.add(res); + } + assertThat(randomList).isNotNull(); + } + +} \ No newline at end of file diff --git a/src/test/java/baseball/service/InputValidServiceTest.java b/src/test/java/baseball/service/InputValidServiceTest.java new file mode 100644 index 0000000000..544b758e11 --- /dev/null +++ b/src/test/java/baseball/service/InputValidServiceTest.java @@ -0,0 +1,75 @@ +package baseball.service; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.in; +import static org.junit.jupiter.api.Assertions.*; + +class InputValidServiceTest { + InputValidService inputValidService =new InputValidService(); + @Test + void isInputValidTest(){ + //given + String str = "123"; + //when + boolean res = inputValidService.isInputValid(str); + //then + assertThat(res).isTrue(); + } + @Test + void isInputValidTest2(){ + //given + String str = "1/3"; + //when + boolean res = inputValidService.isInputValid(str); + //then + assertThat(res).isFalse(); + } + @Test + void isInputValidTEst3(){ + //given + String str = "1"; + inputValidService.updateStatus(); + //when + boolean res = inputValidService.isInputValid(str); + //then + assertThat(res).isTrue(); + } + @Test + void isInputValidTEst4(){ + //given + String str = "="; + inputValidService.updateStatus(); + //when + boolean res = inputValidService.isInputValid(str); + //then + assertThat(res).isFalse(); + } + + @Test + void updateStatusTest(){ + boolean res = inputValidService.endGame; + inputValidService.updateStatus(); + assertThat(inputValidService.endGame).isEqualTo(!res); + } + + @Test + void continueOrEndGameTest(){ + //given + String str = "1"; + //when + boolean res = inputValidService.continueOrEndGame(str); + //then + assertThat(res).isTrue(); + } + @Test + void continueOrEndGameTest2(){ + //given + String str = "2"; + //when + boolean res = inputValidService.continueOrEndGame(str); + //then + assertThat(res).isFalse(); + } +} \ No newline at end of file diff --git a/src/test/java/baseball/service/ServiceTest.java b/src/test/java/baseball/service/ServiceTest.java new file mode 100644 index 0000000000..e02f610fcd --- /dev/null +++ b/src/test/java/baseball/service/ServiceTest.java @@ -0,0 +1,43 @@ +package baseball.service; + +import baseball.model.RandomPickData; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class ServiceTest { + RandomPickData randomPickData = new RandomPickData(); + Service service = new Service(); + + @Test + void judgementTest(){ + //given + String str = "123"; + List ls = randomPickData.getRandomList(); + //when + String res = service.judgement(str, ls); + for(int i=0; i<3; i++){ + ls.get(i); + } + //then + assertThat(res).isNotNull(); + } + @Test + void judgementTest2(){ + //given + String str = "123"; + List ls = new ArrayList<>(); + for(int i=0; i<3; i++){ + ls.add(str.substring(i,i+1)); + } + //when + String res = service.judgement(str, ls); + //then + assertThat(res).isEqualTo("3스트라이크 "); + } + +} \ No newline at end of file