-
Notifications
You must be signed in to change notification settings - Fork 1
/
Car.java
59 lines (48 loc) · 1.39 KB
/
Car.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
package com.yurii.salimov.lesson02.task01;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class Car {
private String name;
private Engine engine;
private Climate climate = new Climate();
private double fuel;
public Car(final String name) {
this.name = name;
this.engine = new Engine(0, 1.0);
}
public Car(final String name, final double mileage, final double volume) {
this.name = name;
this.engine = new Engine(mileage, volume);
}
@Override
public String toString() {
return getName() + ": distance - " + getMileage() + " km, fuel rate - " + getFuel() + " liters.";
}
public void turnOn() {
this.engine.turnOn();
this.climate.turnOn();
this.climate.setTemperature(21);
}
public void turnOff() {
this.engine.turnOff();
this.climate.turnOff();
}
public void start(final int speed, final double hours) {
if (this.engine.isStarted()) {
final double distance = hours * speed;
this.engine.addMileage(distance);
this.fuel += distance * engine.getFuelRate() / 100;
}
}
public String getName() {
return this.name;
}
public double getMileage() {
return this.engine.getMileage();
}
public double getFuel() {
return this.fuel;
}
}