-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathVehicle.java
More file actions
43 lines (34 loc) · 895 Bytes
/
Vehicle.java
File metadata and controls
43 lines (34 loc) · 895 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
public class Vehicle {
private String make;
private String model;
private double speedInKmh;
private static int numberOfVehicles;
public Vehicle(String make, String model) {
this.make = make;
this.model = model;
Vehicle.numberOfVehicles++;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public double getSpeedInKmh() {
return speedInKmh;
}
public static int getNumberOfVehicles() {
return Vehicle.numberOfVehicles;
}
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;
}
}