File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ public enum Engine {
2+
3+ DIESEL ("Diesel" ),
4+ PETROL ("Benzin" ),
5+ GAS ("Gas" ),
6+ ELECTRO ("Elektro" );
7+
8+ private String description ;
9+
10+ Engine (String description ) {
11+ this .description = description ;
12+ }
13+
14+ public String getDescription () {
15+ return description ;
16+ }
17+
18+ }
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ public static void main(String[] args) {
55 numberOfVehicles = Vehicle .getNumberOfVehicles ();
66 System .out .println ("Anzahl Fahrzeuge: " + numberOfVehicles );
77
8- Vehicle vehicle1 = new Vehicle ("Porsche" , "911" );
9- Vehicle vehicle2 = new Vehicle ("MAN" , "TGX" );
10- Vehicle vehicle3 = new Vehicle ("Opel" , "Zafira Life" );
8+ Vehicle vehicle1 = new Vehicle ("Porsche" , "911" , Engine . ELECTRO );
9+ Vehicle vehicle2 = new Vehicle ("MAN" , "TGX" , Engine . DIESEL );
10+ Vehicle vehicle3 = new Vehicle ("Opel" , "Zafira Life" , Engine . DIESEL );
1111
1212 numberOfVehicles = Vehicle .getNumberOfVehicles ();
1313 System .out .println ("Anzahl Fahrzeuge: " + numberOfVehicles );
Original file line number Diff line number Diff line change @@ -2,12 +2,14 @@ public class Vehicle {
22
33 private String make ;
44 private String model ;
5+ private Engine engine ;
56 private double speed ;
67 private static int numberOfVehicles ;
78
8- public Vehicle (String make , String model ) {
9+ public Vehicle (String make , String model , Engine engine ) {
910 this .make = make ;
1011 this .model = model ;
12+ this .engine = engine ;
1113 numberOfVehicles ++;
1214 }
1315
@@ -19,6 +21,10 @@ public String getModel() {
1921 return model ;
2022 }
2123
24+ public Engine getEngine () {
25+ return engine ;
26+ }
27+
2228 public static int getNumberOfVehicles () {
2329 return numberOfVehicles ;
2430 }
@@ -34,6 +40,7 @@ public void brake(int value) {
3440 }
3541
3642 public void print () {
37- System .out .println (make + " " + model );
43+ System .out .println (make + " " + model + " (" + engine . getDescription () + ")" );
3844 }
45+
3946}
You can’t perform that action at this time.
0 commit comments