We have that $F(y) = \displaystyle \int_{-\infty}^y f(x) dx$. In your case, we are given that $$f(x) = \begin{cases} 0 & x <-1\\ 1 + x & x \in[-1,0]\\ 1-x & x \in [0,1]\\ 0 & x > 1\end{cases}$$
- If $y < -1$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^y 0 dx =0 $. We have the integrand $f(x) = 0$ since $x \leq y < -1$.
- If $y \in [-1,0]$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^{-1} f(x) dx + \displaystyle \int_{-1}^{y} f(x) dx$. Since, $f(x) = 0$ for all $x < -1$, we get that $$F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-1}^{y} f(x) dx = \displaystyle \int_{-1}^{y} \left( 1+x \right) dx = \left( x + \frac{x^2}{2} \right)_{-1}^{y} $$
$$F(y) = \left(y + \frac{y^2}{2} \right( - \left( -1 + \frac12 \right) = \frac12 + y + \frac{y^2}{2}.$$
- If $y \in [0,1]$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^{-1} f(x) dx + \displaystyle \int_{-1}^{0} f(x) dx + \displaystyle \int_{0}^{y} f(x) dx$. Since, $f(x) = 0$ for all $x < -1$, we get that $$F(y) = \displaystyle \int_{-1}^{0} f(x) dx + \displaystyle \int_{0}^{y} f(x) dx = \displaystyle \int_{-1}^{0} \left( 1+x \right) dx + \displaystyle \int_{0}^{y} (1-x) dx$$
Hence, $$F(y) = \frac12 + \left( x - \frac{x^2}{2}\right)_0^{y} = \frac12 + y - \frac{y^2}{2}$$
- For $y > 1$, since $f(x) = 0$ for all $x>1$, we have that $F(y) = F(1)$ for all $y > 1$. Hence, $F(y) = F(1) = 1$.
Hence, $$F(y) = \begin{cases} 0 & y <-1\\ \frac12 + y + \frac{y^2}{2} & y \in[-1,0]\\ \frac12 + y - \frac{y^2}{2} & y \in[0,1]\\ 1 & y > 1\end{cases}$$
You're actually going to have a problem with this approach: the original CDF isn't continuous, which means that your random variable isn't continuous and won't have a genuine density function. You can see what the issue will be by considering, for instance, the behavior at $x = 3$; note that the behavior of the CDF implies that $\mathbb P(X = 3) = 1/8$, which isn't something that continuous random variables do.
If your random variable was continuous, your approach would have been perfect for finding the density; but if you integrate the density you obtained, note that it doesn't give a total area of 1. You'll need to change your approach somewhat to proceed....
So, the original idea (which was good and will work in many important situations!) didn't work here. What to do?
This random variable is a hybrid of a discrete and a continuous random variable. It has discrete jumps at $x = 1/2$ and $x = 3$, but its CDF is continuous everywhere else.
The "density" you found will be helpful, because even though it doesn't have a total area of $1$, its area is $5/8$. Note also that the respective probabilities of the random variable being $1/2$ and $3$ are $1/4$ and $1/8$ -- meaning that in total, we've accounted for all the probability ($5/8 + 1/4 + 1/8 = 1$).
Remember what expected value is supposed to be: for a discrete variable, it's
$$\sum_{\text{all possible values}} \text{[value]} \cdot \mathbb P(X \text{ assumes that value})$$
and for a continuous variable it's
$$\int_{-\infty}^{\infty} x \cdot f(x) \, \textrm d x$$
where $f(x)$ is the density function. You might guess (correctly) that a mixed approach will work here:
$$\mathbb E[X] = \frac 1 2 \cdot \mathbb P(X = 1/ 2) + 3 \cdot \mathbb P(X = 3) + \int_{-\infty}^{\infty} x \cdot f(x) \, \textrm d x$$
where $f(x)$ is the not-quite-a-density-function you correctly found in your original post.
I think this approach is challenging to prove / justify at a non-measure-theoretic level, but hopefully it at least makes some intuitive sense; you're capturing the full range of what $X$ can do, and appropriately weighting each possible value of $X$ against its density function.
Best Answer
You are right, there is a mass of $\frac 1 2$ at $x = 1$.
For your question on how to write such a PDF and what value it has at $x = 1$, here are two hints that might help you:
1) You can add a dirac delta function to your PDF.
2) The PDF must integrate to 1.