Expectation value for an energy measurement on an ensemble of particles, Quantum mech

I have the soloution to this question, but am confused as to what has been done between each step between lines 2,3,4. Can anyone explain how they have been simplified (espicially what happened to the operator) and what the value of the intergral is? I think im just missing something here...

Any help would be greatly appreciated!

Leo

The Question and solution are as follows,

Suppose, an ensemble of particles of mass, M, is prepared in a state as below

The Wave function = [tex]\sqrt{\frac{2}{L}}[/tex] cos ([tex]\frac{\Pi x}{L}[/tex] Between L/2 and -L/2, and is 0 otherwise.

Evaluate the expectation value {H} [tex]\psi[/tex] for an energy measurement on an en-
semble of particles prepared in [tex]\psi[/tex] (x)

The Solution

The soloution is shown in the reply below, for somereason, it wouldn't write it all out here. Exscuse the poor latex. PLease also note that h= h bar and the intergral is between limits of L/2 and -L/2