Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
07dd4ec
refactor : refactored anonymous class to Lambda expression
choincnp Apr 22, 2025
0cdb9c6
refactor : add functional interface and refactored to use anonymous cโ€ฆ
choincnp Apr 22, 2025
5286c1b
refactor : replace Anonymous class to lambda expression
choincnp Apr 22, 2025
9421723
refactor : implement stream methods
choincnp Apr 22, 2025
9bdd075
refactor : using optional method to filter results - 1
choincnp Apr 22, 2025
c0f7bf5
refactor : using optional method to filter results - 2
choincnp Apr 22, 2025
a305a44
refactor : using optional method to filter results - 3
choincnp Apr 22, 2025
605a7bb
test : Add domain - Line and some invariants test
choincnp Apr 22, 2025
78384d2
test : Add domain - Ladder and add prototype test
choincnp Apr 22, 2025
bf5c875
refactor : split into small entity
choincnp Apr 23, 2025
d935f02
feat : Add I/O class / method
choincnp Apr 23, 2025
2a8c926
feat : Refactor I/O class/method
choincnp Apr 24, 2025
d9d7c82
refactor : change outputs into fixed type, use strategy pattern
choincnp Apr 24, 2025
c661e70
Merge branch 'step2' into step3
choincnp Apr 24, 2025
d5ced35
refactor : change I/O views and modified some logics
choincnp Apr 24, 2025
5b00ec9
Merge branch 'choincnp' into step3
choincnp Apr 24, 2025
ac7dfaf
refactor : 1์ฐจ ๋ฆฌํŒฉํ† ๋ง, index ๊ตฌ์กฐ์—์„œ ๊ฐ์ฒดํ˜•์‹์œผ๋กœ
choincnp May 5, 2025
672fac7
refactor : ์ปค๋งจ๋“œ ๋ถ„๋ฆฌ์— ๋”ฐ๋ฅธ validation ๋ณ€๊ฒฝ
choincnp May 5, 2025
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
29 changes: 24 additions & 5 deletions src/main/java/nextstep/Main.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
package nextstep;

import nextstep.domain.Ladder;
import nextstep.domain.Names;
import nextstep.view.InputView;
import nextstep.view.OutputView;

import java.util.List;

import nextstep.domain.Bonus;
import nextstep.domain.Ladder;
import nextstep.domain.LadderResult;
import nextstep.domain.Name;
public class Main {
public static void main(String[] args) {
/* I/O ์„ ์–ธ */
InputView in = new InputView();
OutputView out = new OutputView();

Names names = in.getName();
List<Bonus> bonus = in.getBonus(names.size());
int height = in.getHeight();

Ladder ladder = Ladder.of(names.size(), height);
out.printResult(names, ladder);
LadderResult result = new LadderResult(ladder);

out.printLadder(names, ladder, bonus);
while (true) {
String target = in.readTarget().trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

target์ด ์›์‹œ๊ฐ์ฒด๋กœ ํฌ์žฅ๋˜๋ฉด ์–ด๋–จ๊นŒ์š”?? ๐Ÿ˜„
์–ด์ฐŒ๋ณด๋ฉด ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ปค๋งจ๋“œ์—ญํ• ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋„๋ฉ”์ธ๋ชจ๋ธ๋กœ ํ‘œํ˜„๋˜๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

// ๋ผˆ๋Œ€๋งŒ ์žˆ๋Š” ์ฝ”๋“œ์ธ์  ๊ฐ์•ˆํ•˜๊ณ  ๋ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :-) 
LadderGameCommand command = LadderGameCommand.parseBy(in.readTarget());
if (command.isAll()) {
// ๊ธฐ์กด์ฝ”๋“œ
}
Name name = Name.of(command.getValue());

๊ทธ๋Ÿผ ๋งŒ์•ฝ์— exit๋‚˜ ์ด๋ฆ„์ด ์•„๋‹Œ index ๋“ฑ๋“ฑ ์ปค๋งจ๋“œ๊ด€๋ จํ•ด์„œ ์ˆ˜์ •์‚ฌํ•ญ์ด ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๊ด€๋ฆฌ๋„ ํŽธํ•˜๊ณ 
"all"์ด ์•„๋‹ˆ๋ผ ์ „์ฒด๋ฅผ ๋ณด์—ฌ๋‹ฌ๋ผ๋Š” ๋ช…๋ น์ด ๋ณ€๊ฒฝ๋˜๋„ ๊ธฐ์กด ์ฝ”๋“œ ์ˆ˜์ • ์—†์ด LadderGameCommand ๊ฐ์ฒด๋งŒ
์ˆ˜์ •ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์กฐ๊ธˆ ๋” ํฌ์žฅํ• ๊ฑธ... ์•„์‰ฝ์Šต๋‹ˆ๋‹ค ใ… 

boolean isAll = "all".equals(target);
if (isAll) {
out.printAllResults(names, result, bonus);
break;
}
Name n = Name.of(target);
int idx = names.unmodifiableNames().indexOf(n);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ „์ฒด์ ์œผ๋กœ index๊ธฐ์ค€์œผ๋กœ ํ•ธ๋“ค๋ง์ด ๋˜๊ณ  ์žˆ๋Š”๋ฐ์š”, List์ด๋‹ˆ ๋‹น์—ฐํžˆ ๊ทธ๋Ÿด ์ˆ˜ ๋ฐ–์— ์—†๋Š”์ ์ด๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜„
๋„๋ฉ”์ธ ๊ฐ์ฒด๋ฅผ ์ž˜ ์ •์˜ํ•˜๊ณ  ์—ญํ• ๊ณผ ์ฑ…์ž„์„ ๋ถ€์—ฌํ•˜๋Š” ๊ฒŒ ๊ฐ€์žฅ ์ค‘์š”ํ•˜์ง€๋งŒ, ๊ฐœ์ธ์ ์œผ๋กœ ๊ทธ ๋‹ค์Œ์€
์‚ฌ์šฉํ•˜๋Š” ๋‹ค๋ฅธ ๊ฐ์ฒด๋“ค์ด๋‚˜ ์„œ๋น„์Šค๋“ค์—๊ฒŒ ํŽธ๋ฆฌํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

Name์„ Participant๊ฐ™์€ ๊ฐ์ฒด๋กœ ์ƒํ–ฅ(?) ์‹œํ‚ค๊ณ  ์ƒ์„ฑํ•  ๋•Œ
๊ทธ๋ƒฅ index๊ฐ’์„ position๊ฐ™์€ ๊ฐ’์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ์–ด๋–จ๊นŒ์š”??

/**
 * ์ด๋ฆ„ ํด๋ž˜์Šค
 */
public class Participant {
    private static final Integer MAX_NAME_LENGTH = 5;
    private final String name;
    private final int position;

๊ทธ๋ฆฌ๊ณ  Names๋„ Participants๋“ฑ์œผ๋กœ ๋ณ€๊ฒฝ๋˜๊ณ  findByName(Participant) ๊ฐ™์€
method๋ฅผ Optional๋กœ ์ œ๊ณตํ•œ๋‹ค๋ฉด ์ด๋ฆ„์ด ์—†์„ ์ˆ˜๋„ ์žˆ๋Š” ์ƒํ™ฉ์— ๋Œ€ํ•ด์„œ ๋ช…์‹œ์ ์œผ๋กœ ํ‘œํ˜„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Optional<Participant> searched = participants.findByName(participant);

์‚ฌ์šฉํ•˜๋Š” ์ชฝ์—์„œ 0์ด๋‚˜ -1์€ ํ†ต์ƒ์ ์œผ๋กœ ํ†ต์šฉ๋˜๋Š” ์˜๋ฏธ์ด๊ธด ํ•ฉ๋‹ˆ๋‹ค๋งŒ
์‚ฌ์‹ค ๊ด€๋ฆฌํ•˜๊ธฐ ๋ฒˆ๊ฑฐ๋กœ์šด ๊ฐ’์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋งค๋ฒˆ ๊ฐ’์ด ์—†๋Š” ์ƒํ™ฉ์ด -1์ธ์ง€ ์ฝ”๋“œ๋ฅผ ๋”ฐ๋ผ๊ฐ€๋ฉด์„œ
ํ™•์ธํ•ด์•ผ ํ•˜๋Š” ๊ฐ’์ž…๋‹ˆ๋‹ค ๐Ÿ˜„
๋ฌผ๋ก  ์˜ˆ์ „ ๋ ˆ๊ฑฐ์‹œ์ฝ”๋“œ๋“ค์€ ์•„์ง๋„ -1์ด๋ฉด ๊ฐ’์ด ์—†๋Š” ์ƒํƒœ๋กœ ํ‘œํ˜„์ด ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค๋งŒ
๋ฒ„์ „์„ ๊ฑฐ๋“ญํ•˜๋ฉด์„œ Optional์ด๋‚˜, Exception์œผ๋กœ ๊ฐœ์„ ๋˜๊ณ  ์žˆ๋Š” ํ˜•ํƒœ๋กœ ๊ฐ€๋…์„ฑ์ด๋‚˜ ์‚ฌ์šฉ์„ฑ์„
๊ฐœ์„ ํ•ด๊ฐ€๋Š” ํ˜•ํƒœ๋ผ์„œ ๊ทธ ๋ถ€๋ถ„๋„ ํ•œ๋ฒˆ ์ฐธ๊ณ ํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ ๋””๋ฏธํ„ฐ ๋ฒ•์น™์ด ์žˆ๋Š”๋ฐ ๊ฐ™์ด ํ•œ๋ฒˆ ๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

https://dundung.tistory.com/203

if (idx < 0) {
out.printPersonalResult(-1, result, bonus);
continue;
}
out.printPersonalResult(idx, result, bonus);
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/nextstep/domain/Bonus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nextstep.domain;

public class Bonus {
private static final Integer MAX_NAME_LENGTH = 5;
private final String bonusName;

public Bonus(String bonusName) {
validate(bonusName);
this.bonusName = bonusName;
}

public static Bonus of(String bonusName) {
return new Bonus(bonusName);
}

private void validate(String input) {
if (input == null || input.trim().isEmpty()) {
throw new IllegalArgumentException("์ด๋ฆ„์€ ๋นˆ ๋ฌธ์ž์—ด์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
if (input.length() > MAX_NAME_LENGTH) {
throw new IllegalArgumentException("์ด๋ฆ„์€ ์ตœ๋Œ€ " + MAX_NAME_LENGTH + "์ž๊นŒ์ง€ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค.");
}
}

@Override
public String toString() {
return bonusName;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์›์‹œ๊ฐ์ฒด ํฌ์žฅ ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘

9 changes: 9 additions & 0 deletions src/main/java/nextstep/domain/Ladder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nextstep.domain;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -39,4 +41,11 @@ public int height() {
public List<Line> lines() {
return Collections.unmodifiableList(lines);
}

public Map<Integer, Integer> result() {
Map<Integer, Integer> result = new HashMap<>();
IntStream.range(0, lines.size())
.forEach(i -> result.put(i, play(i)));
return result;
}
}
26 changes: 26 additions & 0 deletions src/main/java/nextstep/domain/LadderResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nextstep.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class LadderResult {
private final Map<Integer, Integer> result;

public LadderResult(Ladder ladder) {
result = ladder.result();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์œ„์—์„œ๋„ ์˜๊ฒฌ๋“œ๋ ธ์ง€๋งŒ Map<Integer, Integer> ํ˜•ํƒœ๋Š” ์‚ฌ์šฉํ•˜๋Š” ์ชฝ์—์„œ๋Š” ์–ด๋–ค ๊ฐ’์ด ๋“ค์–ด์žˆ๋Š”์ง€
๋ช…์‹œ์ ์œผ๋กœ ์•Œ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋งค๋ฒˆ ์ด์ชฝ์— ์™€์„œ ๋ฌด์Šจ ๊ฐ’์ด ๋“ค์–ด๊ฐ€๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•˜๋Š” ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  Integer๋ผ๋ฉด ๋ฌด์Šจ ๊ฐ’์ด๋“  ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํƒ€์ž…์•ˆ์ •์„ฑ ์ธก๋ฉด์—์„œ๋„ ์ฒดํฌ ๋˜๋Š”๊ฒŒ
์ข€ ๋” ์•ˆ์ „ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

Map<Participant, Bonus> ์ด๋Ÿฐ์‹์œผ๋กœ ์ œ๊ณต๋˜๋ฉด
index๋กœ ๋ฌผ์–ด๋ณด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ LadderResult์—๊ฒŒ ์ด๋ฆ„์„
์ฃผ๋ฉด ๋ฐ”๋กœ Bonus๋ฅผ ์•Œ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์–ด๋–ป๊ฒŒ ๋ณด์‹œ๋‚˜์š” ๐Ÿ˜„

}

public List<Bonus> getOrderedBonuses(List<Bonus> bonusList) {
List<Bonus> ordered = new ArrayList<>(bonusList.size());
for (int i = 0; i < bonusList.size(); i++) {
int bonusIndex = result.get(i);
ordered.add(bonusList.get(bonusIndex));
}
return ordered;
}

public int get(int index) {
return result.get(index);
}
}
7 changes: 3 additions & 4 deletions src/main/java/nextstep/domain/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ public static Name of(String name) {
return new Name(name);
}

public String getName() {
return name;
}

private void validate(String input) {
if (input == null || input.trim().isEmpty()) {
throw new IllegalArgumentException("์ด๋ฆ„์€ ๋นˆ ๋ฌธ์ž์—ด์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
if (input.length() > MAX_NAME_LENGTH) {
throw new IllegalArgumentException("์ด๋ฆ„์€ ์ตœ๋Œ€ " + MAX_NAME_LENGTH + "์ž๊นŒ์ง€ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค.");
}
if (input.equals("all")) {
throw new IllegalArgumentException("์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์œ„์—์„œ๋„ ์˜๊ฒฌ ๋“œ๋ ธ์ง€๋งŒ, Name๊ณผ Command๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„์ด ๋ฉ๋‹ˆ๋‹ค ๐Ÿ˜„
ALL์ด๋ผ๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ์‚ฌ๋žŒ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฆ„์„ ๋Œ๋ ค์ฃผ์‹œ์ฃ  ๐Ÿ˜†

}

@Override
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/nextstep/domain/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import java.util.stream.IntStream;
/**
* ์ „์ฒด ์ธ์›
*/
Expand Down Expand Up @@ -40,6 +41,10 @@ private List<Name> makeNamesStringToList(String names) {
public int size() {
return names.size();
}

public int getIndex(Name name) {
return names.indexOf(name);
}

public List<Name> unmodifiableNames() {
return Collections.unmodifiableList(names);
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/nextstep/view/InputView.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package nextstep.view;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

import nextstep.domain.Bonus;
import nextstep.domain.Name;
import nextstep.domain.Names;

/**
* ์ž…๋ ฅ ํด๋ž˜์Šค
*/
public class InputView {
private static final int MAX_NAME_LENGTH = 5;
private final Scanner scanner = new Scanner(System.in);

/** ์ฐธ์—ฌ ์ธ์› ์ž…๋ ฅ */
Expand All @@ -22,7 +26,36 @@ public Names getName() {
public int getHeight() {
System.out.println("์ตœ๋Œ€ ์‚ฌ๋‹ค๋ฆฌ ๋†’์ด๋Š” ๋ช‡ ๊ฐœ์ธ๊ฐ€์š”?");
int height = scanner.nextInt();
scanner.nextLine();
return height;
}

public List<Bonus> getBonus(int count) {
System.out.println("์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. (๊ฒฐ๊ณผ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„ํ•˜์„ธ์š”)");
String bonus = scanner.nextLine();
return parseBonus(bonus, count);
}

public String readTarget() {
System.out.println("๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ณ  ์‹ถ์€ ์‚ฌ๋žŒ์€?");
String target = scanner.nextLine();
return target;
}

/** ๊ฒฐ๊ณผ ํŒŒ์‹ฑ */
private List<Bonus> parseBonus(String input, int count) {
List<Bonus> bonus = splitAndTrim(input);
// ๋ณด๋„ˆ์Šค ๊ฐœ์ˆ˜ validation
if (bonus.size() != count) {
throw new IllegalArgumentException("๋ณด๋„ˆ์Šค ๊ฐœ์ˆ˜๋Š” ์‚ฌ๋žŒ ์ˆ˜์™€ ์ผ์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}
return bonus;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๊ฒ€์ฆ ์ฝ”๋“œ ๋„ˆ๋ฌด ์ข‹์€๋ฐ OutputView์— ์žˆ์œผ๋ฉด ์•ˆ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
Bonus๋„ ์ผ๊ธ‰์ปฌ๋ ‰์…˜์œผ๋กœ ๊ฐ€๊ณ  ๊ทธ์ชฝ์— ์œ„์ž„ํ•˜์‹œ๋Š”๊ฑธ ์ถ”์ฒœ ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๐Ÿ™‡


private List<Bonus> splitAndTrim(String input) {
return Arrays.stream(input.split(","))
.map(String::trim)
.map(Bonus::new)
.collect(Collectors.toList());
}
}
52 changes: 45 additions & 7 deletions src/main/java/nextstep/view/OutputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.List;

import nextstep.domain.Bonus;
import nextstep.domain.Ladder;
import nextstep.domain.LadderResult;
import nextstep.domain.Line;
import nextstep.domain.Name;
import nextstep.domain.Names;
Expand All @@ -16,24 +18,59 @@ public class OutputView {
private static final int WIDTH = 5;

/** ๊ฒฐ๊ณผ */
public void printResult(Names names, Ladder ladder) {
System.out.println("์‹คํ–‰ ๊ฒฐ๊ณผ");
public void printLadder(Names names, Ladder ladder, List<Bonus> bonusList) {
System.out.println("์‚ฌ๋‹ค๋ฆฌ ๊ฒฐ๊ณผ");

// 1) ์ด๋ฆ„ ์ค„
System.out.println(formatNameLine(names));

// 2) ์‚ฌ๋‹ค๋ฆฌ ์ค„
ladder.lines().forEach(line ->
System.out.println(formatLadderLine(line))
);
ladder.lines()
.forEach(line -> System.out.println(formatLadderLine(line)));

// 3) ๋ณด๋„ˆ์Šค
System.out.println(formatBonusLine(bonusList));
}

/**
* ๋‹จ์ผ ๊ฒฐ๊ณผ
*/
public void printPersonalResult(int index, LadderResult result, List<Bonus> bonusList) {
System.out.println("์‹คํ–‰ ๊ฒฐ๊ณผ");
if (index == -1) {
System.out.println("๊ฒŒ์ž„์— ์ฐธ์—ฌํ•˜์ง€ ์•Š์€ ์‚ฌ๋žŒ์ž…๋‹ˆ๋‹ค.");
return;
}
System.out.println(bonusList.get(result.get(index)));
}

/**
* all ์กฐํšŒ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
*/
public void printAllResults(Names names, LadderResult result, List<Bonus> bonuses) {
System.out.println("์‹คํ–‰ ๊ฒฐ๊ณผ");
for (int i = 0; i < names.size(); i++) {
Name name = names.unmodifiableNames().get(i);
Bonus bonus = bonuses.get(result.get(i));
System.out.printf("%s : %s%n", name, bonus);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์œ„์—์„œ๋„ ์˜๊ฒฌ๋“œ๋ ธ์ง€๋งŒ, Participant(=Name)๊ฐ€ name๊ณผ index๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋‹ค๋ฉด
participants(=names)๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ ๋ฐ”๋กœ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

}

/** ์ด๋ฆ„ formatting */
private static String formatNameLine(Names names) {
StringBuilder sb = new StringBuilder();
for (Name name : names.unmodifiableNames()) {
sb.append(" ")
.append(padLeft(name.toString()));
.append(padLeft(name.toString()));
}
return sb.toString();
}

private static String formatBonusLine(List<Bonus> bonusList) {
StringBuilder sb = new StringBuilder();
for (Bonus bonus : bonusList) {
sb.append(" ")
.append(padLeft(bonus.toString()));
}
return sb.toString();
}
Expand All @@ -53,7 +90,8 @@ private static String formatLadderLine(Line line) {

/** ์ขŒ์ธก ๊ณต๋ฐฑ */
private static String padLeft(String s) {
if (s.length() >= WIDTH) return s;
if (s.length() >= WIDTH)
return s;
return " ".repeat(WIDTH - s.length()) + s;
}
}