-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car.java
110 lines (83 loc) · 1.85 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
public class Car {
private int currentSpeed;
private String model;
private static String buildPlace = "Germany";
private static int countInst;
//private int maxGears = 6;
private int currentGear = 0;
public Car() {
countInst += 1;
}
public static String getBuildPlace() {
return buildPlace;
}
private void accelerateOffSet(int offset) {
this.currentSpeed += offset;
}
private void changeGear(int gear) {
this.currentGear = gear;
}
private void checkGear() {
if(this.currentSpeed < 20) {
changeGear(1);
}else if (this.currentSpeed < 60) {
changeGear(2);
}else if (this.currentSpeed < 80) {
changeGear(3);
}else if (this.currentSpeed < 100) {
changeGear(4);
}else if (this.currentSpeed < 120) {
changeGear(5);
}else{
changeGear(6);
}
}
public void accelerateGeared() {
if (this.currentGear == 0) {
checkGear();
}else if (this.currentGear == 1) {
accelerateOffSet(3);
checkGear();
}else if (this.currentGear == 2){
accelerateOffSet(10);
checkGear();
}else if (this.currentGear == 3){
accelerateOffSet(20);
checkGear();
}else if (this.currentGear == 4){
accelerateOffSet(30);
checkGear();
}else if (this.currentGear == 5){
accelerateOffSet(40);
checkGear();
}else if (this.currentGear == 6){
accelerateOffSet(50);
checkGear();
}
}
public void decelerate() {
if (this.currentSpeed > 5) {
this.currentSpeed -= 5;
}else{
this.currentSpeed = 0;
}
}
public int getCurrentSpeed() {
return currentSpeed;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public static int getCountInst() {
return countInst;
}
public static void setCountInst(int countInst) {
Car.countInst = countInst;
}
public int getCurrentGear() {
return currentGear;
}
}