-
Notifications
You must be signed in to change notification settings - Fork 1
/
Engine.java
57 lines (47 loc) · 1.26 KB
/
Engine.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
package com.yurii.salimov.lesson02.task01;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class Engine {
private double mileage;
private boolean started;
private double volume;
public Engine(final double mileage, final double volume) {
this.mileage = mileage;
this.volume = volume;
}
public double getFuelRate() {
int rate = 0;
if ((this.volume >= 1.0) && (this.volume <= 2.0)) {
rate = 10;
} else if ((this.volume > 2.0) && (this.volume <= 3.0)) {
rate = 15;
} else if ((this.volume > 3.0) && (this.volume <= 4.0)) {
rate = 20;
} else if ((this.volume > 4.0) && (this.volume <= 5.0)) {
rate = 25;
}
return rate;
}
public double getMileage() {
return this.mileage;
}
public void addMileage(final double mileage) {
if (mileage > 0 && isStarted()) {
this.mileage += mileage;
}
}
public boolean isStarted() {
return this.started;
}
public void turnOn() {
this.started = true;
}
public void turnOff() {
this.started = false;
}
public double getVolume() {
return this.volume;
}
}