How much work can a force on a spring do? (Why are two methods wrong?) This was a question my friend found in a book.

A block attached to a spring pulled by a constant horizontal force is kept on a smooth horizontal surface. Initially the spring is in its natural state. Then the maximum work that the applied force F can do is:

(a) $F^2/k$
(b) $2F^2/k$
(c) $4F^2/k$
(d) $F^2/2k$

My friend thought that the answer is (a) since the maximum displacement is $x=F/k$ and $W=Fx=F^2/k$. But he saw that the book's answer is different and he asked this question to me.
I at first thought that the answer will be (a), but then I realised that this situation is somewhat similar to a charging capacitor. The final energy of the spring is actually $\frac12kx^2=F^2/2k$. So probably the answer is (d)? But the work done is still (a)? But the book says neither. It's (b). This is the logic in the book:

Method 1: in the book: 
$$Fx=\frac12kx^2$$ 
$$x=2F/k$$ 
$$W=\frac12kx^2=2F^2/k$$ 
(since the book is an objective questions book it did not have detailed explanations)

What is wrong in the following methods?

Method 2: by calculating the maximum displacement 
$$x=F/k$$ 
$$W=Fx=F^2/k.$$
Method 3: by calculating the final energy 
$$x=F/k$$ 
$$\frac12kx^2=F^2/2k$$

PS: We both know calculus so don't hesitate to use it in the answers.
 A: I have tried to give the background to the solution given in the textbook.

The energy stored or released is given by $\int \vec f \cdot d \vec  x$ and the important thing to note is that the force $\vec f$ varies with extension $\vec x$.
This relationship is usually written as $\vec f = - k \vec x$ with the force $\vec f$ being the force exerted by the spring on an external object, so the relationship for an (external) force acting on the spring has a positive sign.
So the energy stored/released is $\displaystyle \int_0^x kx \,dx = \frac 12 kx^2$

Let the static extension of the spring when a force $F$ is applied be $x_o$ and so $F=kx_o$ and the energy stored in the spring is $\frac 12 kx^2_o$.
The situation in the problem is different in that a constant force $F$ is applied and the work done by the force in moving to the static extension position is $Fx_o$.
In moving the mass to that static extension position the force $F$ has also accelerated the mass.
So the mass also has kinetic energy which must be accounted for if one needs to find the total work done by the force $F$ in terms of $k$ and $F$.
Now the kinetic energy must be the work done by the force $Fx_o= kx^2_o$ minus the energy stored in the spring $\frac 12 kx^2_o$.
So the kinetic energy is $\frac 12 kx^2_o$.
Note that although the net force on the mass at the static extension position is zero the mass is moving and so overshoots the static equilibrium position and the force $F$ continues to do work as the direction of the applied force and its displacement are still in the same direction.

Let the extension when the mass finally stops be $x_{\max}$.
This happens when the work done by the force is all stored as potential energy in the spring $FX=\frac12kx_{\max}^2$ and this is the equation given in the textbook's solution.   
Using $F=kx_o$ gives $x_{\max}= 2x_o$.
So the maximum work done by the force $F$ is $F\,2x_o=\dfrac{2F^2}{k}$
A: While the other answers might already show why the books solution is correct, here another point of view that might help:
What is the net force on the object?
$$F_{net} = F + F_{spring}$$
$$= F - kx$$
This is the formula that gives you the equilibrium position of $x_0=F/k$, so let's shift our coordinate system a bit so that $x'_0=0$, i.e. $x' = x - F/k$.
What is now the net force in our new coordinate system, where the equilibrium is at 0?
$$F_{net} = F - kx$$
$$= F - k(x' + F/k)$$
$$= -kx'$$
Oh wait, in this coordinate system the force on the object is proportional to its displacement - that's a harmonic oscillator!
The starting position is the maximum displacement in one direction and as we know from harmonic oscillators, the maximum displacement in the other direction is equal in distance, so the full range this object swings is $x_{max}=2 F/k$.
Together with the usual formula of $W=Fx_{max}$ you get the same result as the book.
You can also choose energy conservation, since all the energy at maximum displacement is stored in the spring and the object is not moving, which is the third line you quoted from the book, $W=\frac{1}{2}kx_{max}^2$. 
This is btw. also the energy of the harmonic oscillator.
Or in short: both your methods work if you choose the correct max. displacement.
A: What's wrong with method 2 as well as method 3 is that 
$$x_{max} = F/k$$  is not valid!
When you are applying force F on the body you are also imparting it with kinetic energy. $x = F/k$ is the displacement at which the net force experienced by it becomes zero, but it does not stop there. It goes on until its velocity goes to zero due to the pull of the spring. 
At that point all its energy is in the form of the potential energy of the spring as given in the solution. 
