-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathRacing.java
More file actions
31 lines (26 loc) · 817 Bytes
/
Racing.java
File metadata and controls
31 lines (26 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package racingcar;
import java.util.ArrayList;
public class Racing {
public void startRace(ArrayList<Car> cars, Integer count) {
for (int i = 0; i < count; i++) {
for (Car c : cars) {
c.move();
System.out.println(c.getName() + " : " + c.getDistance());
}
System.out.println();
}
int max = 0;
for (Car c : cars) {
if (c.getDistanceLength() > max) {
max = c.getDistanceLength();
}
}
ArrayList<String> names = new ArrayList<>();
for (Car c : cars) {
if (c.getDistanceLength() == max) {
names.add(c.getName());
}
}
System.out.println("최종 우승자 : " + String.join(",", names));
}
}