In case 1 the A travels the distance D while traveling from X to Y.
In case 2 the velocity of A according to Sam will 'a' and distance travelled by A will be greater than D because the wall Y is also moving away. According to wall X velocity of ball is a-v and distance travelled by A will be D because Frame of reference of X is same as Case 1.
My question is in Case 2 how can two observer Sam and wall X measure different distances? Is it possible?