-
Notifications
You must be signed in to change notification settings - Fork 52
red.is #54
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
Open
coolofficials
wants to merge
10
commits into
next-step:main
Choose a base branch
from
coolofficials:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
red.is #54
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa29092
docs: 구현할 기능 목록 업데이트 (README.md)
89855e1
feat: Console
coolofficials 0894477
feat: Engine
coolofficials 2b8ea40
feat: generateNumber in Pitcher
coolofficials 8703e75
style: fit to Java code convention
coolofficials 8272343
feat: Referee
coolofficials 0821d5d
test: PitcherTest, RefereeTest
coolofficials 15107da
chore: remove string test
coolofficials 94e5b49
docs: Updated To-do
coolofficials 9f88cfa
fix: remove usage of else statement
coolofficials File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package baseball; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Console { | ||
| public String getInput() { | ||
| System.out.print("숫자를 입력해주세요 : "); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.next(); | ||
| } | ||
|
|
||
| public void printResult(int strike, int ball) { | ||
| if (strike + ball == 0) { | ||
| System.out.print("낫씽"); | ||
| } | ||
| if (strike != 0) { | ||
| System.out.print(strike + " 스트라이크 "); | ||
| } | ||
| if (ball != 0) { | ||
| System.out.print(ball + " 볼"); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public int endGame() { | ||
| System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); | ||
| System.out.println("게임을 새로 시작하시려면 1, 종료하려면 2를 입력하세요."); | ||
| Scanner scanner = new Scanner(System.in); | ||
| return scanner.nextInt(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package baseball; | ||
|
|
||
| public class Controller { | ||
| public static void main(String[] args) { | ||
| Engine engine = new Engine(); | ||
| engine.playBall(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package baseball; | ||
|
|
||
| public class Engine { | ||
| public void playBall() { | ||
| int flag = 1; | ||
| while (flag == 1) { | ||
| flag = match(); | ||
| } | ||
| } | ||
|
|
||
| private int match() { | ||
| Console console = new Console(); | ||
| Pitcher pitcher = new Pitcher(); | ||
| String target = pitcher.generateNumber(); | ||
| batting(console, target); | ||
| return console.endGame(); | ||
| } | ||
|
|
||
| private void batting(Console console, String target) { | ||
| int strike = 0; | ||
| int ball; | ||
| Referee referee = new Referee(); | ||
| while (strike != 3) { | ||
| String input = console.getInput(); | ||
| int[] result = referee.judge(target, input); | ||
| strike = result[0]; | ||
| ball = result[1]; | ||
| console.printResult(strike, ball); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package baseball; | ||
| import java.util.Random; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
|
|
||
| public class Pitcher { | ||
| public String generateNumber() { | ||
| Random random = new Random(); | ||
| ArrayList<Integer> digits = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); | ||
| StringBuilder number = new StringBuilder(); | ||
| for (int i = 0; i < 3; i++) { | ||
| int randomIndex = random.nextInt(digits.size()); | ||
| number.append(digits.get(randomIndex)); | ||
| digits.remove(randomIndex); | ||
| } | ||
| return number.toString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package baseball; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Referee { | ||
| public int[] judge(String target, String input) { | ||
| return new int[] {countStrike(convert(target), convert(input)), countBall(convert(target), convert(input))}; | ||
| } | ||
|
|
||
| private List<Integer> convert(String string) { | ||
| List<Integer> career = new ArrayList<>(); | ||
| for(String number: string.split("")) { | ||
| career.add(Integer.parseInt(number)); | ||
| } | ||
| return career; | ||
| } | ||
|
|
||
| private int countBall(List<Integer> target, List<Integer> input) { | ||
| int ball = 0; | ||
| if (target.get(0) == input.get(1) || target.get(0) == input.get(2)) { | ||
| ball++; | ||
| } | ||
| if (target.get(1) == input.get(0) || target.get(1) == input.get(2)) { | ||
| ball++; | ||
| } | ||
| if (target.get(2) == input.get(0) || target.get(2) == input.get(1)) { | ||
| ball++; | ||
| } | ||
| return ball; | ||
| } | ||
|
|
||
| private int countStrike(List<Integer> target, List<Integer> input) { | ||
| int strike = 0; | ||
| if (target.get(0) == input.get(0)) { | ||
| strike ++; | ||
| } | ||
| if (target.get(1) == input.get(1)) { | ||
| strike ++; | ||
| } | ||
| if (target.get(2) == input.get(2)) { | ||
| strike ++; | ||
| } | ||
| return strike; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package baseball; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| public class PitcherTest { | ||
| Pitcher pitcher; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| pitcher = new Pitcher(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("랜덤 세자리 숫자 생성 확인") | ||
| void lengthTest() { | ||
| String number = pitcher.generateNumber(); | ||
| assertThat(3).isEqualTo(number.length()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package baseball; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| public class RefereeTest { | ||
| Referee referee; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| referee = new Referee(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("스트라이크 볼 판단 확인") | ||
| void judgeTest() { | ||
| assertThat(new int[] {2, 0}).isEqualTo(referee.judge("123", "125")); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
띄어쓰기가 빠져야함.