Frankie and Johnny game. What should Johnny strategy if he wants to minimize his expected loss? Frankie and Johnny play the following game.
Frankie selects a number at random from the interval
$[a, b]$. Johnny, not knowing Frankie’s number, is to pick
a second number from that same inverval and pay Frankie
an amount, W, equal to the squared difference between
the two
[so $0 ≤ W ≤ (b − a)^2]$. What should be Johnny’s
strategy if he wants to minimize his expected loss?
Attempt: Let $Y$ be Frankie's choice. 
Then Johnny wants to choose $k$ so that $E(Y - k)^2$ is minimize. 
Can someone please help me? I am having trouble. The answer is Johnny should pick $(a+b)/2$ to minimize his loss.

The simplest approach is to just expand the expectation and minimize. So $$E[(Y-k)^2]=E[Y^2]-E[2kY]+E[k^2].$$ Assuming the second moment of $Y$ is finite, we take the derivative with respect to $k$ and set equal to zero. $$-2E[Y]+2k=0,$$ or $$k = E[Y].$$
Note that we have yet to use any distribution. This holds for all distributions with finite second moment. Now for a continuous uniform random variable on $[a,b]$ the mean is $$\mu = {{a+b} \over {2}} $$ so that is the optimal value of $k.$ The second derivative confirms this provides the minimum. 
