Given force = 40 pounds
Unstretched length of spring= 12 in
initial compression= s₁ =3 in
Now, first we find the spring constant K from the above given conditions;
F=K*s₁
(40)= K*(3)
K= 13.333 pounds/in
Now, the final compression makes the spring length= 4 in so the final compression from the unstretched lenght = s₂=8 in
Work done= 1/2K(s₂)² - 1/2K(s₁)²
= 1/2(13.333)(8)² - 1/2(13.333)(3)²
= 366.58 pounds*in