-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInputOutput.java
More file actions
58 lines (44 loc) · 1.75 KB
/
InputOutput.java
File metadata and controls
58 lines (44 loc) · 1.75 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package racingcar;
import camp.nextstep.edu.missionutils.Console;
public class InputOutput {
private int carCount = 0;
private String[] carNames;
public String[] readCarNames(){
System.out.print("차량들의 이름을 입력하세요: ( ,로 구별해주세요.)");
String names = Console.readLine();
carNames = names.split(", ");
carCount = carNames.length;
if(carCount <=1 ) throw new IllegalArgumentException("차량의 이름을 2개 이상 입력해주세요.");
return carNames;
}
public int readDriveCount(){ // 횟수가 1 이상의 정수여야 함. done
System.out.print("횟수를 입력하세요: ");
String input = Console.readLine();
try{
carCount = Integer.parseInt(input);
} catch(NumberFormatException e){
throw new IllegalArgumentException("type error: 1 이상의 정수를 입력해주세요.");
}
if(carCount <= 0) throw new IllegalArgumentException("0보다 큰 정수여야 합니다.");
return carCount;
}
public void printRoundResult(int[] moveCount){
for(int i =0; i < carCount; i++){
System.out.print(carNames[i] + " : " );
for(int j =0; j < moveCount[i]; j++){
System.out.print("-");
}
System.out.println();
}
}
public void printWinner(String[] winnerList){
if(winnerList.length == 1) System.out.println("최종 우승자: " + winnerList[0]);
else {
System.out.print("최종 우승자: " + winnerList[0]);
for(int i = 1; i < winnerList.length; i++) System.out.print(", " + winnerList[i]);
}
}
public int getCarCount() {
return carCount;
}
}