-
Notifications
You must be signed in to change notification settings - Fork 140
/
Saab95.java
79 lines (63 loc) · 1.69 KB
/
Saab95.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
import java.awt.*;
public class Saab95{
public boolean turboOn;
public int nrDoors; // Number of doors on the car
public double enginePower; // Engine power of the car
public double currentSpeed; // The current speed of the car
public Color color; // Color of the car
public String modelName; // The car model name
public Saab95(){
nrDoors = 2;
color = Color.red;
enginePower = 125;
turboOn = false;
modelName = "Saab95";
stopEngine();
}
public int getNrDoors(){
return nrDoors;
}
public double getEnginePower(){
return enginePower;
}
public double getCurrentSpeed(){
return currentSpeed;
}
public Color getColor(){
return color;
}
public void setColor(Color clr){
color = clr;
}
public void startEngine(){
currentSpeed = 0.1;
}
public void stopEngine(){
currentSpeed = 0;
}
public void setTurboOn(){
turboOn = true;
}
public void setTurboOff(){
turboOn = false;
}
public double speedFactor(){
double turbo = 1;
if(turboOn) turbo = 1.3;
return enginePower * 0.01 * turbo;
}
public void incrementSpeed(double amount){
currentSpeed = getCurrentSpeed() + speedFactor() * amount;
}
public void decrementSpeed(double amount){
currentSpeed = getCurrentSpeed() - speedFactor() * amount;
}
// TODO fix this method according to lab pm
public void gas(double amount){
incrementSpeed(amount);
}
// TODO fix this method according to lab pm
public void brake(double amount){
decrementSpeed(amount);
}
}