-
Notifications
You must be signed in to change notification settings - Fork 140
/
Volvo240.java
68 lines (54 loc) · 1.56 KB
/
Volvo240.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
import java.awt.*;
public class Volvo240{
public final static double trimFactor = 1.25;
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 Volvo240(){
nrDoors = 4;
color = Color.black;
enginePower = 100;
modelName = "Volvo240";
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 double speedFactor(){
return enginePower * 0.01 * trimFactor;
}
public void incrementSpeed(double amount){
currentSpeed = Math.min(getCurrentSpeed() + speedFactor() * amount,enginePower);
}
public void decrementSpeed(double amount){
currentSpeed = Math.max(getCurrentSpeed() - speedFactor() * amount,0);
}
// 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);
}
}