forked from oopd-gu-chalmers/lab1
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSaab95.java
More file actions
42 lines (37 loc) · 1003 Bytes
/
Copy pathSaab95.java
File metadata and controls
42 lines (37 loc) · 1003 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
import java.awt.*;
public class Saab95 extends Cars{
private boolean turboOn;
public Saab95(){
super(2, 125, Color.red, "Saab95");
turboOn = false;
}
public void setTurboOn(){
turboOn = true;
}
public void setTurboOff(){
turboOn = false;
}//används ej
public boolean isTurboOn(){
return turboOn;
}
private double speedFactor(){
double turbo = 1;
if(turboOn) turbo = 1.3;
return getEnginePower() * 0.01 * turbo;
}
@Override
protected void incrementSpeed(double amount){
currentSpeed = getCurrentSpeed() + speedFactor() * amount;
if(currentSpeed>getEnginePower()){
currentSpeed = getEnginePower();
}
}
@Override
protected void decrementSpeed(double amount){
if(currentSpeed <= speedFactor() * amount){
currentSpeed = 0;
}else{
currentSpeed = getCurrentSpeed() - speedFactor() * amount;
}
}
}