-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathCar.java
More file actions
46 lines (35 loc) · 826 Bytes
/
Car.java
File metadata and controls
46 lines (35 loc) · 826 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
36
37
38
39
40
41
42
43
44
45
46
public class Car {
int position = 0;
public int carNumber;
public String carName;
public Car() {
this.position = 0;
}
public Car(int carNumber, String carName) {
this.carNumber = carNumber;
this.carName = carName;
}
public int getRandom() {
double randomValue = Math.random();
return (int) (randomValue * 9);
}
public boolean getStatus() {
int randomValue = getRandom();
boolean result = true;
if (randomValue <= 3) {
result = false;
}
return result;
}
public void tryMove() {
if(getStatus()) {
this.position++;
}
}
public int getPosition() {
return position;
}
public String getCarName() {
return carName;
}
}