-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathCar.java
40 lines (31 loc) · 879 Bytes
/
Car.java
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
package edu.nextstep.camp.carracing;
public class Car {
private static final int MOVE_THRESHOLD = 4;
private static final String MOVE_SYMBOL = "-";
private final CarName name;
private int position;
public Car(String name) {
this(name, 0);
}
public Car(String name, int position) {
this.name = new CarName(name);
this.position = position;
}
public void move(int number) {
if (number >= MOVE_THRESHOLD) {
position++;
}
}
public String getCurrentPositionString() {
return String.format("%s : %s", name.getName(), MOVE_SYMBOL.repeat(position));
}
public boolean isMaxPosition(int position) {
return this.position == position;
}
public CarName getName() {
return name;
}
public int getPosition() {
return position;
}
}