-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Step4 리뷰 요청드립니다. #5528
Open
ZhenxiKim
wants to merge
11
commits into
next-step:zhenxikim
Choose a base branch
from
ZhenxiKim:step4
base: zhenxikim
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.
+170
−17
Open
Step4 리뷰 요청드립니다. #5528
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
217d833
test: 자동차 경주 테스트 코드 작성
32fcbe5
feat: 자동차 경주 코드 개발
6308e65
feat: 리뷰 반영
8f7f303
feat: 리뷰 반영
2ccff9b
feat: new line 추가
71bf0c9
feat: 리뷰 반영
0d9dc58
feat: step4 구현
5136683
feat: step4 구현
0347467
Merge branch 'zhenxikim' into step4
ZhenxiKim 5021299
feat: step4 구현
3bfa13f
feat: indent 수정
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 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
- [X] 생선된 자동차 수는 1보다 크다. | ||
- [X] 전진하는 조건은 0에서 9 사이에서 random 값을 구한 후 random 값이 4이상일 경우이다. | ||
- [X] 자동차 이름은 5자를 초과할 수 없다. | ||
- [X] 우승자는 한명 이상일 수 있다. | ||
|
This file contains 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 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 @@ | ||
import java.util.List; | ||
|
||
/** | ||
* @author jeongheekim | ||
* @date 3/27/24 | ||
*/ | ||
public class FormattingUtil { | ||
private FormattingUtil() {} | ||
|
||
public static String formattingResult(List<String> list) { | ||
StringBuilder sb = new StringBuilder(); | ||
int size = list.size(); | ||
for (int i = 0; i < size; i++) { | ||
sb.append(list.get(i)); | ||
if (i < size - 1) { | ||
sb.append(","); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
인덴트가 2이상이군요 🤔 |
||
return sb.toString(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -8,51 +8,65 @@ | |
public class Game { | ||
|
||
public static final String DELIMETER = "-"; | ||
|
||
public static final String CAR_NAME_DELIMETER = ","; | ||
|
||
private int gameCount; | ||
|
||
private Car[] cars; | ||
|
||
public void start() { | ||
cars = createCar(); | ||
|
||
cars = createCar(); | ||
|
||
gameCount = getGameCount(); | ||
System.out.println("실행 결과"); | ||
for (int i = 0; i < gameCount; i++) { | ||
job(); | ||
} | ||
|
||
Winner winner = new Winner(); | ||
System.out.println(FormattingUtil.formattingResult(winner.getWinners(cars)) + "가 최종 우승했습니다."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
} | ||
|
||
private void job() { | ||
for (Car car : this.cars) { | ||
car.drive(car.getNumber(), DELIMETER); | ||
System.out.println(car.getStatus()); | ||
System.out.println(car.getName() + ":" + car.getStatus()); | ||
} | ||
System.out.println(" "); | ||
} | ||
|
||
private int getGameCount() { | ||
Scanner scanner = new Scanner(System.in); | ||
System.out.println("시도할 회수는 몇 회 인가요?"); | ||
|
||
int gameCount = scanner.nextInt(); | ||
System.out.println("gameCount = " + gameCount); | ||
System.out.println(gameCount); | ||
|
||
return gameCount; | ||
} | ||
|
||
|
||
private Car[] createCar() { | ||
int carCount = getCarCount(); | ||
Car[] cars = new Car[carCount]; | ||
for (int i = 0; i < carCount; i++) { | ||
cars[i] = new SmallCar(); | ||
String[] carNameInputArr = getCarNameInputArr(); | ||
int length = carNameInputArr.length; | ||
Car[] cars = new Car[length]; | ||
for (int i = 0; i < length; i++) { | ||
cars[i] = new SmallCar(carNameInputArr[i]); | ||
|
||
} | ||
return cars; | ||
} | ||
|
||
private int getCarCount() { | ||
System.out.println("자동차 대수는 몇 대 인가요?"); | ||
|
||
private String[] getCarNameInputArr() { | ||
System.out.println("경주할 자동차 이름을 입력하세요(이름은 " + CAR_NAME_DELIMETER + "를 기준으로 구분)."); | ||
Scanner scanner = new Scanner(System.in); | ||
int carCount = Integer.parseInt(scanner.nextLine()); | ||
System.out.println("자동차 대수 = " + carCount); | ||
return carCount; | ||
String carNameInput = scanner.nextLine(); | ||
System.out.println(carNameInput); | ||
return carNameInput.split(CAR_NAME_DELIMETER); | ||
} | ||
|
||
public Car[] getCars() { | ||
|
This file contains 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 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,35 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author jeongheekim | ||
* @date 3/26/24 | ||
*/ | ||
public class Winner { | ||
private List<String> winners = new ArrayList<>(); | ||
private int maxLength; | ||
|
||
public void addWinner(String name) { | ||
this.winners.add(name); | ||
} | ||
|
||
public void updateMaxLength(int length) { | ||
this.maxLength = length; | ||
} | ||
|
||
public List<String> getWinners(Car[] cars) { | ||
List<String> winners = new ArrayList<>(); | ||
for (Car car : cars) { | ||
this.filterMaxLength(car); | ||
} | ||
return winners; | ||
} | ||
|
||
private void filterMaxLength(Car car) { | ||
int statusLength = car.getStatus().length(); | ||
if (this.maxLength <= statusLength) { | ||
this.updateMaxLength(statusLength); | ||
this.addWinner(car.getName()); | ||
} | ||
} | ||
} |
This file contains 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 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,29 @@ | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author jeongheekim | ||
* @date 3/27/24 | ||
*/ | ||
class WinnerTest { | ||
|
||
@Test | ||
@DisplayName("우승자는 한명 이상이다.") | ||
void winnerLengthTest() { | ||
SmallCar car = new SmallCar("pobi"); | ||
car.drive(7, "-"); | ||
|
||
Car[] cars = new Car[1]; | ||
cars[0] = car; | ||
|
||
Winner winner = new Winner(); | ||
List<String> winners = winner.getWinners(cars); | ||
|
||
assertTrue(winners.size() >= 1); | ||
} | ||
|
||
} |
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.
👍