-
Notifications
You must be signed in to change notification settings - Fork 6
java-racingcar 미션 제출 #4
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
chae-heechan
wants to merge
52
commits into
biforest:chae-heechan
Choose a base branch
from
chae-heechan:main
base: chae-heechan
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
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
0a5d963
docs: 기능 구현 목록 및 클래스 정리
chae-heechan 216cb6d
test: 입력 및 유효성 검사 클래스 테스트 케이스 작성
chae-heechan ae04e19
feat: Receiver 클래스 구현
chae-heechan a6e8c0f
feat: Validator 인터페이스 생성
chae-heechan 804fe2d
docs: 클래스 분류 재정리
chae-heechan a02977d
feat: Message인터페이스 생성
chae-heechan 3ac806d
test: validator클래스 구조 변경에 따른 테스트 변경
chae-heechan a973407
feat: 출력 메세지 인터페이스 작성
chae-heechan 78bb06d
refactor: 메세지 호출 메서드 삭제, 입력 예외 추가
chae-heechan bb9c87b
feat: 프린터 클래스 구현
chae-heechan 07f6628
feat: 게임 시작 기능 추가
chae-heechan cdfc826
docs: 클래스 및 메서드 분류 재정리
chae-heechan 0ff13cc
feat: Car클래스 구현
chae-heechan 6519379
feat: Message클래스 구현
chae-heechan 7aaac17
feat: Validator클래스 구현
chae-heechan b115436
refactor: receiveLine 메서드 삭제
chae-heechan 8d840f7
feat: 게임 실행 부분 구현
chae-heechan 74d8054
feat: 난수 생성 기능 구현
chae-heechan 02b5186
style: overSizeCharacters 메서드 이름 변경
chae-heechan 6954307
test: Paramiterizedtest로 변경
chae-heechan 305ea0d
feat: 게임 내 출력 메서드 추가
chae-heechan fc3b773
test: Receiver 테스트 케이스 작성
chae-heechan e0fe4fa
docs: Paramiterized 테스트 사용하기 위해 testCompile 부분 추가
chae-heechan 2d34588
style: overSizeCharacters 메서드 이름 변경
chae-heechan e1c98f3
style: 불필요한 라인 제거
chae-heechan 38feeaa
test: Car 테스트 케이스 작성
chae-heechan c47f82f
test: GamePlayer 테스트 케이스 작성
chae-heechan 2c62d0c
test: Generator 테스트 케이스 작성
chae-heechan 838a38b
test: Message 테스트 케이스 작성
chae-heechan 1a10b46
test: Printer 테스트 케이스 작성
chae-heechan d9fbd3a
style: overSizeCharacters 메서드 이름 변경
chae-heechan 932e5fe
feat: 게임 내 출력 메서드 추가
chae-heechan ed3d8ac
test: Receiver 테스트 케이스 작성
chae-heechan e0b9f8d
feat: 게임 내 출력 메서드 추가
chae-heechan 0b4dd36
refactor: 출력 부분 printer 객체에서 처리하도록 변경
chae-heechan 7bb1ace
docs: empty 파일 삭제
chae-heechan 6a4411c
refactor: 인터페이스 내의 불필요한 코드 삭제
chae-heechan b1b4155
refactor: 객체 접근지정자 변경
chae-heechan 6c66206
refactor: 불필요한 생성자 제거
chae-heechan 4bead01
refactor: 클래스 내의 선언 순서 변경
chae-heechan 8320e5c
refactor: 쉼표(,) 상수로 변경
chae-heechan ca1d01b
refactor: 생성자 삭제
chae-heechan 87e63b3
refactor: 메소드 이름 변경
chae-heechan b338bea
refactor: 정규식 상수로 표현 변경
chae-heechan d1ce820
refactor: 반복문에 사용되는 변수 이름 변경
chae-heechan 874421e
refactor: 상수 이름 변경
chae-heechan 329c805
refactor: inputOtherThanCharacter 메서드 이름 변경
chae-heechan d947ed2
refactor: 접근지정자 명시
chae-heechan 4f7ee17
refactor: isCorrectName 메서드 이름 변경
chae-heechan 0d2f2fd
refactor: 객체에 final 키워드 추가
chae-heechan da7d13f
refactor: GamePlayer의 car객체 생성 역할을 CarManager로 분산
chae-heechan a7b2e8b
refactor: GamePlayer의 우승자 판독 역할을 Referee로 분산
chae-heechan 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
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 @@ | ||
| import domain.GamePlayer; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args){ | ||
| GamePlayer gamePlayer = new GamePlayer(); | ||
| gamePlayer.run(); | ||
| } | ||
| } |
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,19 @@ | ||
| package domain; | ||
|
|
||
| import io.Receiver; | ||
|
|
||
| public class CarManager { | ||
| private final Receiver receiver = new Receiver(); | ||
|
|
||
| public Car[] produceCar(){ | ||
| String[] listOfName = receiver.receiveName(); | ||
|
|
||
| Car[] cars = new Car[listOfName.length]; | ||
| for (int i = 0; i < listOfName.length; i++) | ||
| cars[i] = new Car(listOfName[i]); | ||
|
|
||
| return cars; | ||
| } | ||
|
|
||
|
|
||
| } |
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,54 @@ | ||
| package domain; | ||
|
|
||
| import io.Printer; | ||
| import io.Receiver; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class GamePlayer { | ||
| private final int WINNER_CONDITION = 4; | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final Printer printer = new Printer(); | ||
| private final Receiver receiver = new Receiver(); | ||
| private final Generator generator= new Generator(); | ||
| private final CarManager carManager = new CarManager(); | ||
| private final Referee referee = new Referee(); | ||
|
|
||
| public void judgeToMove(Car car, int randomNumber) { | ||
| if (randomNumber >= WINNER_CONDITION) | ||
| car.moveForward(); | ||
| } | ||
|
|
||
| public int receiveRepeatCount() { | ||
| printer.printGeneralMessage("INPUT_COUNT"); | ||
| return receiver.receiveNumber(); | ||
| } | ||
|
|
||
| public void launchAllRound(Car[] cars, int countRound) { | ||
| for (int i = 0; i < countRound; i++) { | ||
| for (Car car : cars) { | ||
| judgeToMove(car, generator.generateRandomNumber()); | ||
| printer.printProgressWithSymbol(car.getName(), car.getPosition()); | ||
| } | ||
| printer.printGeneralMessage("DEFAULT_SPACE"); | ||
|
|
||
| try { | ||
| Thread.sleep(500); | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void run() { | ||
| printer.printGeneralMessage("INPUT_NAMEOFCAR"); | ||
| Car[] cars = carManager.produceCar(); | ||
| int countRound = receiveRepeatCount(); | ||
|
|
||
| printer.printGeneralMessage("OPERATION_RESULT"); | ||
| launchAllRound(cars, countRound); | ||
|
|
||
| List<Car> winner = referee.checkWinner(cars); | ||
| printer.printWinner(printer.makeWinnerToString(winner)); | ||
| } | ||
| } | ||
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,9 @@ | ||
| package domain; | ||
|
|
||
| public class Generator { | ||
| private static final int MAX_LIMIT_NUMBER = 10; | ||
|
|
||
| public int generateRandomNumber() { | ||
| return (int) ((Math.random() * 10000) % MAX_LIMIT_NUMBER); | ||
| } | ||
| } |
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,32 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Referee { | ||
| private int maxNumber = 0; | ||
| private final List<Car> result = new ArrayList<>(); | ||
|
|
||
| public List<Car> checkWinner(Car[] cars) { | ||
| findMaxNumber(cars); | ||
| judgeWinner(cars); | ||
| return result; | ||
| } | ||
|
|
||
| public void findMaxNumber(Car[] cars) { | ||
| int firstPlacePosition = maxNumber; | ||
|
|
||
| for (Car car : cars) { | ||
| if (car.getPosition() > firstPlacePosition) | ||
| firstPlacePosition = car.getPosition(); | ||
| } | ||
| maxNumber = firstPlacePosition; | ||
| } | ||
|
|
||
| public void judgeWinner(Car[] cars) { | ||
| for (Car car : cars) { | ||
| if (car.getPosition() == maxNumber) | ||
| result.add(car); | ||
| } | ||
| } | ||
| } |
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,103 @@ | ||
| package domain; | ||
|
|
||
| import io.Printer; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class Validator implements ValidatorInterface { | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static final int MAX_NAME_SIZE = 5; | ||
| private static final String ONLY_NUMBER = "^[0-9]+$"; | ||
| private static final String COMMA_IN_A_ROW = "^(,,)+$"; | ||
| private static final String OTHER_THAN_CHARACTER = "^[a-zA-Z,]+$"; | ||
|
|
||
| Printer printer = new Printer(); | ||
|
|
||
| @Override | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public boolean isCorrectName(String s) { | ||
| return inputNothing(s) | ||
| && inputCommaInARow(s) | ||
| && inputOtherThanCharacter(s) | ||
| && startWithComma(s) | ||
| && endWithComma(s) | ||
| && overSizeCharacters(s) | ||
| && inputSameName(s); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean validateNumber(String s) { | ||
| return s.matches(ONLY_NUMBER); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inputNothing(String s) { | ||
| if (s.equals("")) { | ||
| printer.printExceptionMessage("INPUT_NOTHING"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inputCommaInARow(String s) { | ||
| if (Pattern.matches(COMMA_IN_A_ROW, s)) { | ||
| printer.printExceptionMessage("INPUT_COMMA_IN_A_ROW"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean startWithComma(String s) { | ||
| if (s.charAt(0) == ',') { | ||
| printer.printExceptionMessage("START_WITH_COMMA"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean endWithComma(String s) { | ||
| if (s.charAt(s.length() - 1) == ',') { | ||
| printer.printExceptionMessage("END_WITH_COMMA"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inputOtherThanCharacter(String s) { | ||
| if (!Pattern.matches(OTHER_THAN_CHARACTER, s)) { | ||
| printer.printExceptionMessage("INPUT_OTHER_THAN_CHARACTERS"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inputSameName(String s) { | ||
| List<String> CAR_NAME_LIST = Arrays.asList(s.split(",")); | ||
| int sizeOfNameList = CAR_NAME_LIST.size(); | ||
|
|
||
| for (int i = 0; i < sizeOfNameList; i++) { | ||
| if (CAR_NAME_LIST.subList(i + 1, sizeOfNameList).contains(CAR_NAME_LIST.get(i))) { | ||
| printer.printExceptionMessage("INPUT_SAME_NAME"); | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean overSizeCharacters(String s) { | ||
| String[] splitName = s.split(","); | ||
| for (String i : splitName) | ||
| if (i.length() > MAX_NAME_SIZE) { | ||
| printer.printExceptionMessage("OVER_SIZE_CHARACTERS"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
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 domain; | ||
|
|
||
| public interface ValidatorInterface { | ||
| boolean isCorrectName(String s); | ||
|
|
||
| boolean validateNumber(String s); | ||
|
|
||
| boolean inputNothing(String s); | ||
|
|
||
| boolean inputCommaInARow(String s); | ||
|
|
||
| boolean startWithComma(String s); | ||
|
|
||
| boolean endWithComma(String s); | ||
|
|
||
| boolean inputOtherThanCharacter(String s); | ||
|
|
||
| boolean inputSameName(String s); | ||
|
|
||
| boolean overSizeCharacters(String s); | ||
| } |
Empty file.
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,42 @@ | ||
| package io; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Message implements MessageInterface { | ||
| Map<String, String> generalMessageList = new HashMap<String, String>(); | ||
| Map<String, String> exceptionMessageList = new HashMap<String, String>(); | ||
|
|
||
| public Message() { | ||
| this.exceptionMessageList(); | ||
| this.generalMessageList(); | ||
| } | ||
| private void generalMessageList() { | ||
| generalMessageList.put("INPUT_NAMEOFCAR", "경주할 자동차 이름을 입력하세요. (이름은 쉼표(,) 기준으로 구분)"); | ||
| generalMessageList.put("INPUT_COUNT", "시도할 회수는 몇회인가요?"); | ||
| generalMessageList.put("OPERATION_RESULT", "실행 결과"); | ||
| generalMessageList.put("FIANL_WINNER", "가 최종 우승했습니다."); | ||
| generalMessageList.put("DEFAULT_SPACE", ""); | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private void exceptionMessageList() { | ||
| exceptionMessageList.put("INPUT_NOTHING", "아무 문자도 입력되지 않았습니다."); | ||
| exceptionMessageList.put("INPUT_COMMA_IN_A_ROW", "쉼표(,)가 연속으로 입력되었습니다."); | ||
| exceptionMessageList.put("INPUT_OTHER_THAN_CHARACTERS", "영어와 쉼표(,) 이외의 다른 문자가 입력되었습니다."); | ||
| exceptionMessageList.put("START_WITH_COMMA", "쉼표(,)로 시작합니다."); | ||
| exceptionMessageList.put("END_WITH_COMMA", "쉼표(,)로 끝납니다."); | ||
| exceptionMessageList.put("INPUT_SAME_NAME", "같은 이름이 입력되었습니다."); | ||
| exceptionMessageList.put("OVER_SIZE_CHARACTERS", "이름이 5자 이상입니다."); | ||
| exceptionMessageList.put("INPUT_CHARACTERS_OTHER_THAN_DIGIT", "숫자 이외의 다른 문자가 입력되었습니다."); | ||
| } | ||
|
|
||
| @Override | ||
| public String selectMessageFromGeneral(String Keyword) { | ||
| return generalMessageList.get(Keyword); | ||
| } | ||
|
|
||
| @Override | ||
| public String selectMessageFromException(String Keyword) { | ||
| return exceptionMessageList.get(Keyword); | ||
| } | ||
| } | ||
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,14 @@ | ||
| package io; | ||
|
|
||
| public interface MessageInterface { | ||
chae-heechan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private void generalMessageList() { | ||
| } | ||
|
|
||
| private void exceptionMessageList() { | ||
| } | ||
|
|
||
| String selectMessageFromGeneral(String Keyword); | ||
|
|
||
| String selectMessageFromException(String Keyword); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.