-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathCar.java
More file actions
35 lines (28 loc) · 848 Bytes
/
Car.java
File metadata and controls
35 lines (28 loc) · 848 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
32
33
34
35
package racingcar;
import camp.nextstep.edu.missionutils.Randoms;
public class Car {
private static final int MOVE_THRESHOLD = 4; // 피드백: 4를 의미있는 상수로
protected String name;
private String distance;
public Car(String Name) {
if (Name == null || Name.length() > 5)
throw new IllegalArgumentException();
this.name = Name;
this.distance = "";
}
public void move() { // 피드백: 접근제어자 명시 (default → public)
int num = Randoms.pickNumberInRange(0, 9);
if (num >= MOVE_THRESHOLD) {
this.distance += "-";
}
}
public String getName() {
return name;
}
public String getDistance() {
return distance;
}
public int getDistanceLength() {
return distance.length();
}
}