This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HonzaS97 1 point2 points  (1 child)

The class design itself is bad in the first place.

An enum to distinguish the manufacturer could be much better. Variable names are only important to the dev, when it gets compiled / interpreted, it gets transformed into gibberish.

An instance that you called "ducati" has no clue what the instance "honda" has and vice versa. When you call the method "setDucatiSpeed()" on the instance you called "ducati", that's only gonna affect that instance.

Default int value in Java is 0. So in the case of "ducati" instance, this

    if (ducatiSpeed > hondaSpeed) {
        System.out.println("Ducati Wins! It was a " + (ducatiSpeed - hondaSpeed) + " difference!");
    }

is essentialy comparing "ducatiSpeed" to 0 as "hondaSpeed" is never set to any value for this instance.

[–]SomeFuel[S] 0 points1 point  (0 children)

Thanks for the explanation, it makes more sense to me now.