Could someone assist me in setting up this equation? Thanks!!

A block of mass 2 kg attached to a spring lies on a flat surface. When the block is pulled 5 cm to the right a force with a magnitude of 340 N is need to hold it in place. What is the work done by the spring when the block moves from x = 8 cm to x = 12 cm. Express your answer in joules.

To set up the equation, we need to use Hooke's Law, which states that the force exerted by a spring is directly proportional to the displacement from its equilibrium position.

First, we need to find the spring constant, denoted by k. The equation for Hooke's Law is given by F = -kx, where F represents the force, k is the spring constant, and x is the displacement from the equilibrium position.

In this problem, we are given that a force of 340 N is needed to hold the block in place when it is pulled 5 cm to the right. Therefore, we can set up the equation as follows:

340 N = -k * 0.05 m

Simplifying the equation, we get:

k = -340 N / 0.05 m
k = -6,800 N/m

Now that we have the spring constant, we can calculate the work done by the spring as the block moves from x = 8 cm to x = 12 cm.

To find the work done, we use the equation W = (1/2) * k * (x2^2 - x1^2), where W represents the work done, k is the spring constant, and x2 and x1 are the final and initial positions, respectively.

Plugging in the values, we get:

W = (1/2) * (-6,800 N/m) * ((0.12 m)^2 - (0.08 m)^2)
W = (1/2) * (-6,800 N/m) * (0.0144 m^2 - 0.0064 m^2)
W = (1/2) * (-6,800 N/m) * 0.008 m^2
W = -27.2 J

Therefore, the work done by the spring when the block moves from x = 8 cm to x = 12 cm is -27.2 joules.