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
distancenotDistance - Same way instance variable name should also start with small letter
bike1and notBike1 - Better to use
this.distancein constructor instead ofDistance = D
5
solved Why does Bike2.getTime() returns a 0 instead of a correct integer value? [closed]