wrote method to calculate the new speed