To solve this problem we need to use the equations related to Elastic Potential Energy, which allows us to know the Energy stored in a spring based on its elastic constant and its respective compression. By definition it is described as
[tex]PE = \frac{1}{2}kx^2[/tex]
Where,
k = Spring constant
x = Displacement
Our values are given as
[tex]x_1= 0.08m[/tex]
As we do not know the spring constant but if the energy stored at the compression given then,
[tex]PE = \frac{1}{2}kx^2[/tex]
[tex]20 = \frac{1}{2}k(0.08)^2[/tex]
[tex]k = 6250N/m [/tex]
In the case of the second compression and understanding that the spring constant is intrinsic to the internal force of the spring, then
[tex]x_2 = 0.12m[/tex]
Replacing,
[tex]PE = \frac{1}{2}(6250)(0.12)^2[/tex]
[tex]PE = 45J[/tex]
Therefore the elastic potential energy in the spring at this elongation is 45J