[Solved] Why does Bike2.getTime() returns a 0 instead of a correct integer value? [closed]


Because it’s integer operation (40/80)*60 will give you 0. Note here that in integer calculation 40/80 will be 0 not 0.5 you need to use double values instead of int in your program to get exact answer (for your particular case).

Some suggestions related to conventions,

  • Choose meaningful name for your class which describe it’s purpose i.e TimeCalculator, Bike
  • Start variable name with small letter distance not Distance
  • Same way instance variable name should also start with small letter bike1 and not Bike1
  • Better to use this.distance in constructor instead of Distance = D

5

solved Why does Bike2.getTime() returns a 0 instead of a correct integer value? [closed]