If given a random variable X whose density is given by the following uniform distribution,
$$p(x)= \begin{cases} 1 & \ 0 <x < 40 \\ \\ 0 & \text{else} \end{cases}$$
the price of x is x^2. Say we wanted to find the expected cost would we integrate like this
$\int_{0}^{40} x^2 * p(x) \,dx$
and take our final answer as the result of this or like this?
$\int_{0}^{40} x * p(x) \,dx$
and then we would square the latter to get the cost?
They seem very similar yet they yield different results. Can anyone explain what the procedure is here and why?