Skip to content

[3단계 - 사다리 타기] 최지수 미션 제출합니다 #68

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

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/ladder/controller/LadderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ladder.model.Ladder;
import ladder.model.LadderBuilder;
import ladder.model.LadderResult;
import ladder.model.LinkConnector;
import ladder.view.LadderOutputView;

Expand Down Expand Up @@ -31,13 +32,14 @@ public void run() {
LadderBuilder ladderBuilder = new LadderBuilder(linkConnector);
Ladder ladder = ladderBuilder.build(width, height);


LadderOutputView ladderOutputView = new LadderOutputView();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13번 줄에서 이미 LadderOutputView 인스턴스를 선언해주셨더라고요!
여기 동일한 객체를 한 번 더 생성하고 계신데 기존 객체를 재사용하시면 중복도 줄이고 코드도 더 명확해질 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그렇네요! 기존에 만든 객체를 다시 사용해볼게요

LadderResult ladderResult = new LadderResult();
List<List<Boolean>> lines = ladder.getLines();

for (List<Boolean> line : lines) {
ladderOutputView.printLine(line);
}

ladderResult.printResult(ladder);
}
}
36 changes: 36 additions & 0 deletions src/main/java/ladder/model/LadderResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ladder.model;

import java.util.List;

public class LadderResult {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputView에서 출력을 담당하고 있는 것으로 보이는데, Result 객체에서도 출력 관련 로직이 있는 이유가 있을까요?
혹시 출력 책임이 두 객체에 나뉘는 구조라면, 역할이 겹치는 부분이 있는지 한 번 정리해봐도 좋을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음에 Controller클래스에서 분리를 했었는데 OutputView에서 출력을 담당하는 부분과 역할이 겹치는 구조네요 이 부분 고쳐볼게요!


public void printResult(Ladder ladder) {
List<List<Boolean>> lines = ladder.getLines();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일급 컬렉션을 만드신걸로 아는데 사용하지 않는 이유가 따로 있을까요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음 요구사항을 만족해주세요~!

일급 컬렉션을 쓴다.

int width = 0;
if (!lines.isEmpty()) {
width = lines.get(0).size() + 1;
}

for (int startLine = 0; startLine < width; startLine++) {
int currentPosition = endPosition(startLine, lines);
System.out.println(startLine + " -> " + currentPosition);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저 번에 StringBuilder를 사용하신 걸로 아는데 이 부분도 StringBuilder 사용하셔도 좋을 것 같아요!

}
}

private int endPosition(int start, List<List<Boolean>> lines) {
int currentPosition = start;
for (List<Boolean> line : lines) {
currentPosition = move(currentPosition, line);
}
return currentPosition;
}

private int move(int currentPosition, List<Boolean> line) {
boolean rightPosition = currentPosition < line.size() && line.get(currentPosition);
boolean leftPosition = currentPosition > 0 && line.get(currentPosition - 1);

if (rightPosition) return currentPosition + 1;
if (leftPosition) return currentPosition - 1;
return currentPosition;
}
Comment on lines +20 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음 요구사항을 만족해보면 좋을것 같아요 :)

Java Enum을 적용한다.

}
26 changes: 26 additions & 0 deletions src/test/java/ladder/model/LadderResultTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ladder.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class LadderResultTest {

@Test
@DisplayName("사다리 위치 출력")
void ladderPositionCheck() {
// 임의로 만든 사다리
List<List<Boolean>> lines = new ArrayList<>();
lines.add(Arrays.asList(false, true));
lines.add(Arrays.asList(false, false));

Ladder ladder = new Ladder(lines);
LadderResult ladderResult = new LadderResult();

ladderResult.printResult(ladder);
}

}