-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteeringWheel.java
More file actions
54 lines (44 loc) · 1.61 KB
/
SteeringWheel.java
File metadata and controls
54 lines (44 loc) · 1.61 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
import java.util.Objects;
public class SteeringWheel {
private float position = 0.0f;
public SteeringWheel(float position) {
this.position = position;
}
public float getPosition() {
return position;
}
public void setPosition(float position) {
this.position = position;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SteeringWheel)) return false;
SteeringWheel that = (SteeringWheel) o;
return Float.compare(that.getPosition(), getPosition()) == 0;
}
@Override
public int hashCode() {
return Objects.hash(getPosition());
}
@Override
public String toString() {
return "SteeringWheel{" +
"position=" + position +
'}';
}
void turn(SteeringWheel steeringWheel) {
final int DEGREE = 3; // ступінна градація оборотів керма
this.position = steeringWheel.position * DEGREE;
if (position == 0)
System.out.println("Їдемо прямо...");
else if (position < 0 && position >= -45)
System.out.println("Ухил вліво...");
else if (position < 0 && position < -45)
System.out.println("Різкий поворот вліво...");
else if (position > 0 && position <= 45)
System.out.println("Ухил вправо...");
else if (position > 0 && position > 45)
System.out.println("Різкий поворот вправо...");
}
}