In your second constructor (the one you're actually using in your main
method)
public Motorcycle(String name, int yearOfProduction, int price, int weight, String color, String engineType, boolean isReadyToDrive, int distance) { // previous statements omitted this.isReadyToDrive = destroyEngine(); this.distance = distance;}
The destroyEngine
methods uses the instance variable distance
to decide whether to return true
or false
. But, as currently written, the distance
instance variable still has its default value of 0.
You have to give it a value before calling destroyEngine
.
public Motorcycle(String name, int yearOfProduction, int price, int weight, String color, String engineType, boolean isReadyToDrive, int distance) { // previous statements omitted this.distance = distance; this.isReadyToDrive = destroyEngine();}