Let the length of the pen be L and the width be W. One of the sides of the pen will be the barn. As we have to maximise the area of the pen that is constructed, the barn should form one of the longer sides of the pen.
Now we have 2W + L = 120
=> L = 120 - 2W
The area of the pen is W*L
=> A = W*(120 - 2W)
=> A = 120W - 2W^2
We differentiate the area with respect to W
dA/dW = 120 - 4W
Equate this to 0
120 - 4W = 0
=> W = 120/4 = 30
L = 120 - 2W = 120 - 60 = 60
The required dimensions of the pen should be length 60 feet and width 30 feet.