-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathVehicle.java
More file actions
49 lines (39 loc) · 1017 Bytes
/
Vehicle.java
File metadata and controls
49 lines (39 loc) · 1017 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
43
44
45
46
47
48
49
public class Vehicle {
private String make;
private String model;
protected double speedInKmh;
private Engine engine;
private static int numberOfVehicles;
public Vehicle(String make, String model, Engine engine) {
this.make = make;
this.model = model;
Vehicle.numberOfVehicles++;
this.engine = engine;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public Engine getEngine() {
return engine;
}
public double getSpeedInKmh() {
return speedInKmh;
}
public void accelerate(int valueInKmh) {
speedInKmh += valueInKmh;
System.out.println(toString() + " beschleunigt auf " + speedInKmh + "km/h");
}
public void brake(int valueInKmh) {
speedInKmh -= valueInKmh;
System.out.println(toString() + " bremst auf " + speedInKmh + "km/h ab");
}
public String toString() {
return make + " " + model;
}
public static int getNumberOfVehicles() {
return Vehicle.numberOfVehicles;
}
}