-
Notifications
You must be signed in to change notification settings - Fork 37
[LBP] 권지후 사다리 2-5단계 미션 제출합니다 #44
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
base: jihoo2002
Are you sure you want to change the base?
Changes from all commits
8ff892d
272e3f3
79a89dd
58449af
a15ea17
61dac53
5894df8
72d6d7d
cf29f3e
8409652
26d4ae4
03c0883
586cbf0
4cc30cc
c7151e9
e7385c6
7a08d40
ed8b69e
62e1bce
8b1cb04
6f4ef52
a2a5707
c3e9176
522379a
8aafd4f
a7f648c
42140af
93c7578
871892e
c2facf9
5ff0bac
5ae6601
2b0164d
1335675
903cbf5
71f176b
3a1f208
1e16ec9
0c4b52f
c938035
2020d05
c678058
34ca870
38a1359
31cca69
70f1f56
8f215c1
9e6496d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package exception; | ||
|
||
public enum ExceptionMessage { | ||
LADDER_HEIGHT_MIN_VALUE("사다리 높이는 최소 2 이상이어야 합니다."), | ||
LADDER_SIZE_NEGATIVE("사다리 사이즈가 0보다 작을 수는 없습니다."), | ||
LADDER_HEIGHT_NOT_NUMBER("사다리 높이는 숫자여야 합니다."), | ||
|
||
PLAYER_NAME_MAX_LENGTH_EXCEEDED("참가자 이름은 최대 5글자를 초과할 수 없습니다."), | ||
MIN_PLAYERS_REQUIRED("참가자는 최소 2명 이상이여야 합니다."), | ||
|
||
RESULT_COUNT_MISMATCH("실행결과 개수와 참가자의 수는 동일해야 합니다."), | ||
RESULT_NOT_NULL_OR_EMPTY("실행결과는 null이거나 공백일 수는 없습니다."), | ||
NULL_OR_EMPTY_INPUT("입력값이 null이거나 비어있을 순 없습니다."); | ||
Comment on lines
+3
to
+13
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. 좋은 시도인 것 같아요. 다만 바뀔 수 있는 규칙에 대해서는 고민해보면 좋을 것 같아요! 👍 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 final String message; | ||
|
||
ExceptionMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package model; | ||
|
||
import exception.ExceptionMessage; | ||
|
||
public class Height { | ||
private static final int MIN_HEIGHT = 2; | ||
|
||
private final int value; | ||
|
||
public Height(int value) { | ||
validateValue(value); | ||
this.value = value; | ||
} | ||
|
||
private void validateValue(int value) { | ||
if (value < MIN_HEIGHT) { | ||
throw new IllegalArgumentException(ExceptionMessage.LADDER_HEIGHT_MIN_VALUE.getMessage()); | ||
} | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package model; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LadderResult { | ||
private static final String NO_RESULT = "결과 없음"; | ||
private final Map<String, String> results; | ||
private final Ladder ladder; | ||
Comment on lines
+8
to
+11
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. 도메인, 출력 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. 도메인 클래스라고 생각합니다 |
||
|
||
public LadderResult(Ladder ladder) { | ||
this.ladder = ladder; | ||
this.results = new HashMap<>(); | ||
} | ||
|
||
public void calculateResults(List<String> playerNames, Prizes prizes) { | ||
List<String> prizeValues = prizes.getPrize(); | ||
|
||
for (String playerName : playerNames) { | ||
int playerIndex = playerNames.indexOf(playerName); | ||
playerIndex = ladder.move(playerIndex); | ||
results.put(playerName, prizeValues.get(playerIndex)); | ||
} | ||
} | ||
|
||
public String getResultForPlayer(String name) { | ||
return results.getOrDefault(name, NO_RESULT); | ||
} | ||
|
||
public Map<String, String> getValue() { | ||
return Collections.unmodifiableMap(results); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package model; | ||
|
||
import exception.ExceptionMessage; | ||
|
||
public class Player { | ||
|
||
private static final int MAX_NAME_LENGTH = 5; | ||
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.
그러나 현재 프로젝트에서는 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 final String value; | ||
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. Player의 value는 무엇일까요? 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. 이 피드백 받고 저도 플레이어 이름을 나타내는 |
||
|
||
public Player(String value) { | ||
validateValues(value); | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
private void validateValues(String value) { | ||
if (value == null || value.trim().isEmpty()) { | ||
throw new IllegalArgumentException(ExceptionMessage.NULL_OR_EMPTY_INPUT.getMessage()); | ||
} | ||
|
||
if (value.length() > MAX_NAME_LENGTH) { | ||
throw new IllegalArgumentException(ExceptionMessage.PLAYER_NAME_MAX_LENGTH_EXCEEDED.getMessage()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||||||||||||||||||
package model; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import exception.ExceptionMessage; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||
|
||||||||||||||||||||||
public class Players { | ||||||||||||||||||||||
|
||||||||||||||||||||||
private static final int MIN_PLAYER_LENGTH = 2; | ||||||||||||||||||||||
private final List<Player> players; | ||||||||||||||||||||||
|
||||||||||||||||||||||
public Players(List<String> players) { | ||||||||||||||||||||||
validatePlayers(players); | ||||||||||||||||||||||
this.players = generatePlayers(players); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public int size() { | ||||||||||||||||||||||
return players.size(); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public List<String> getPlayers() { | ||||||||||||||||||||||
return players.stream() | ||||||||||||||||||||||
.map(Player::getValue) | ||||||||||||||||||||||
.toList(); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
private List<Player> generatePlayers(List<String> players) { | ||||||||||||||||||||||
return players.stream() | ||||||||||||||||||||||
.map(Player::new) | ||||||||||||||||||||||
.toList(); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+27
to
+31
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.
Suggested change
더 명확히 써볼 수 있을 것 같아요. 😄 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 validatePlayers(List<String> players) { | ||||||||||||||||||||||
if (players.size() < MIN_PLAYER_LENGTH) { | ||||||||||||||||||||||
throw new IllegalArgumentException(ExceptionMessage.MIN_PLAYERS_REQUIRED.getMessage()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package model; | ||
|
||
import exception.ExceptionMessage; | ||
|
||
public class Prize { | ||
|
||
private final String value; | ||
|
||
public Prize(String value) { | ||
validateValue(value); | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
private void validateValue(String value) { | ||
if (value == null || value.trim().isEmpty()) { | ||
throw new IllegalArgumentException(ExceptionMessage.RESULT_NOT_NULL_OR_EMPTY.getMessage()); | ||
} | ||
} | ||
} |
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.
"all" 이라는 문자열 리터럴이 모든 플레이어들을 나타낸다고 생각하니 어색한 것 같아요. 어떻게 생각하시나요?
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.
미션 LMS에 실행결과에서의 예시가
all
로 명시되어 있어all
이라는 문자값을 넣어주되 상수 명을ALL_PLAYERS
라고 명시해줬습니다 !