-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeedForSpeed.java
More file actions
41 lines (33 loc) · 914 Bytes
/
Copy pathNeedForSpeed.java
File metadata and controls
41 lines (33 loc) · 914 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
class NeedForSpeed {
int speed, batteryDrain, distance, battery = 100;
NeedForSpeed(int speed, int batteryDrain) {
this.speed = speed;
this.batteryDrain = batteryDrain;
}
public boolean batteryDrained() {
return battery - batteryDrain < 0;
}
public int distanceDriven() {
return this.distance;
}
public void drive() {
if (batteryDrained()) {
return;
}
distance = distance + speed;
battery = battery - batteryDrain;
}
public static NeedForSpeed nitro() {
return new NeedForSpeed(50, 4);
}
}
class RaceTrack {
int distance;
RaceTrack(int distance) {
this.distance = distance;
}
public boolean canFinishRace(NeedForSpeed car) {
car.drive();
return car.batteryDrained() ? car.distanceDriven() >= distance : canFinishRace(car);
}
}