-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathOutputView.java
More file actions
41 lines (32 loc) · 1 KB
/
OutputView.java
File metadata and controls
41 lines (32 loc) · 1 KB
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
32
33
34
35
36
37
38
39
40
41
package view;
import domain.Car;
import domain.Cars;
import java.util.ArrayList;
import java.util.List;
public class OutputView {
// 결과 출력
public static void printRacing(List<Car> cars){
for (Car car : cars){
System.out.print(car.getCarName() + " : ");
for (int i = 0; i < car.getCarPosition(); i++)
System.out.print("-");
System.out.println();
}
System.out.println();
}
// 우승자 출력
public static void printWinner(List<Car> cars){
int max = 0;
List<String> winners = new ArrayList<>();
for (Car car : cars){
if (car.getCarPosition() > max)
max = car.getCarPosition();
}
for (Car car : cars){
if (car.getCarPosition() == max)
winners.add(car.getCarName());
}
String winnerResult = String.join(", ", winners);
System.out.println(winnerResult + "가 최종 우승했습니다.");
}
}