-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 각 자동차가 이동 후 결과를 가지고있는 VO CarResult 구현 2. InputValueDto 대신 게임 정보를 가지고있는 GameInformation 로 변경
- Loading branch information
Showing
16 changed files
with
135 additions
and
179 deletions.
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
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 @@ | ||
package racing.domain; | ||
|
||
|
||
public class CarResult implements Comparable { | ||
private static final int COMPARE_EQUAL = 0; | ||
private static final int COMPARE_SMALL = -1; | ||
private String name; | ||
private int distance; | ||
|
||
public CarResult(String name, int distance) { | ||
this.name = name; | ||
this.distance = distance; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getDistance() { | ||
return distance; | ||
} | ||
|
||
@Override | ||
public int compareTo(Object o) { | ||
CarResult target = (CarResult) o; | ||
|
||
int compare = Integer.compare(target.distance, this.distance); | ||
// | ||
// if (compare == COMPARE_EQUAL) { | ||
// return COMPARE_SMALL; | ||
// } | ||
|
||
return compare; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
package racing.domain; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
public class PhaseResult { | ||
private final Map<String, Integer> raceResults; | ||
private final List<CarResult> raceResults; | ||
|
||
public PhaseResult(Map<String, Integer> raceResults) { | ||
public PhaseResult(List<CarResult> raceResults) { | ||
this.raceResults = raceResults; | ||
} | ||
|
||
public Map<String, Integer> getRaceResults() { | ||
public List<CarResult> getRaceResults() { | ||
return raceResults; | ||
} | ||
|
||
public List<String> getCurrentLeads() { | ||
int max = raceResults.entrySet().stream() | ||
.mapToInt(Map.Entry::getValue) | ||
.max() | ||
.orElseThrow(IllegalStateException::new); | ||
CarResult currentLead = raceResults.stream() | ||
.sorted() | ||
.findFirst() | ||
.orElseThrow(IllegalAccessError::new); | ||
|
||
return raceResults.entrySet().stream() | ||
.filter(x -> x.getValue() == max) | ||
.map(Map.Entry::getKey) | ||
return raceResults.stream() | ||
.filter(carResult -> carResult.getDistance() == currentLead.getDistance()) | ||
.map(CarResult::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,30 @@ | ||
package racing.dto; | ||
|
||
public class GameInformation { | ||
private String[] namesOfCars; | ||
private int numberOfAttempts; | ||
|
||
public GameInformation(String[] namesOfCars, int numberOfAttempts) { | ||
validateInputValue(namesOfCars, numberOfAttempts); | ||
this.namesOfCars = namesOfCars; | ||
this.numberOfAttempts = numberOfAttempts; | ||
} | ||
|
||
public int getNumberOfAttempts() { | ||
return numberOfAttempts; | ||
} | ||
|
||
public String[] getNamesOfCars() { | ||
return namesOfCars; | ||
} | ||
|
||
private void validateInputValue(String[] namesOfCars, int numberOfAttempts) { | ||
if (namesOfCars.length <= 0) { | ||
throw new IllegalArgumentException("입력된 자동차 이름의 개수는 0 보다 커야합니다."); | ||
} | ||
|
||
if (numberOfAttempts <= 0) { | ||
throw new IllegalArgumentException("시도할 횟수는 0 보다 커야합니다."); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,36 +1,24 @@ | ||
package racing.view; | ||
|
||
import racing.dto.InputValueDto; | ||
|
||
import java.util.Scanner; | ||
|
||
public class InputView { | ||
private static final Scanner scanner = new Scanner(System.in); | ||
private static final String DELIMETER = ","; | ||
|
||
public static InputValueDto getInputValueWithName() { | ||
public static int inputNumberOfAttempts() { | ||
System.out.println("시도할 횟수는 몇 회 인가요?"); | ||
try { | ||
String[] namesOfCars = inputNameOfCars().split(DELIMETER); | ||
int numberOfAttempts = Integer.parseInt(inputNumberOfAttempts()); | ||
|
||
return new InputValueDto(namesOfCars, numberOfAttempts); | ||
return Integer.parseInt(scanner.nextLine()); | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException("숫자를 입력해주세요."); | ||
throw new IllegalArgumentException("숫자르 입력해주세요."); | ||
} | ||
} | ||
|
||
public static String inputNumberOfCars() { | ||
System.out.println("자동차 대수는 몇 대 인가요?"); | ||
return scanner.nextLine(); | ||
} | ||
|
||
public static String inputNumberOfAttempts() { | ||
System.out.println("시도할 횟수는 몇 회 인가요?"); | ||
return scanner.nextLine(); | ||
} | ||
|
||
public static String inputNameOfCars() { | ||
public static String[] inputNameOfCars() { | ||
System.out.println("경주할 자동차 이름을 입력하세요. (이름은 쉼표(,)를 기준으로 구분)"); | ||
return scanner.nextLine(); | ||
String names = scanner.nextLine(); | ||
|
||
return names.split(DELIMETER); | ||
} | ||
} |
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
Oops, something went wrong.