Skip to content

Commit 7454c9f

Browse files
committed
feat(Application) : 승자 확인함수 작성
가장 먼거리를 구하고, 해당 거리만큼 이동한 모든 차량을 반환 Related to : Dcom-KHU#6
1 parent e6c8dbe commit 7454c9f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/racingcar/Application.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ private void checkTurnValid(int turn) {
3636
}
3737
}
3838

39+
private List<Car> getWinners(){
40+
List<Car> winners = new ArrayList<>();
41+
int maxPosition = 0;
42+
for (Car car : cars) {
43+
maxPosition = Math.max(maxPosition, car.getPosition());
44+
}
45+
for (Car car : cars) {
46+
if (car.getPosition() == maxPosition) {
47+
winners.add(car);
48+
}
49+
}
50+
return winners;
51+
}
52+
3953
public static void main(String[] args) {
4054
}
4155
}

0 commit comments

Comments
 (0)