The general solution for u is
\begin{equation*}u = \phi(x+3t) + \psi(x-3t)\end{equation*}
Now impose the initial conditions (2) and (3)
\begin{align}
&\phi(x) + \psi(x) = f(x)\\
&\phi'(x) + \psi'(x) = g(x)\end{align}
Solve the above to give
\begin{align}
&\phi(x) = \frac{1}{2}f(x) + \frac{1}{6}\int_{0}^{x} g(x') dx' \\
&\psi(x) = \frac{1}{2}f(x) - \frac{1}{6}\int_{0}^{x} g(x') dx'\end{align}
Therefore, when x > 3t,
\begin{equation}u(x) = \phi(x+3t) + \psi(x-3t) = \frac{1}{2}[f(x+3t) + f(x-3t)] + \frac{1}{6}\int_{x-3t}^{x+3t} g(x') dx'\end{equation}
To find what u is when x<3t, impose initial condition (4)
\begin{equation*}\phi'(3t) + \psi'(-3t) = h(t)\end{equation*}
Which implies
\begin{equation*}\phi(3t) - \psi(-3t) = 3\int_{0}^{t} h(t') dt' + C\end{equation*}
Let $x =-3t, x<0, t = -\frac{x}{3}$
\begin{equation*}\phi(-x) - \psi(x) = 3\int_{0}^{-x/3} h(t')dt' + C\\
\psi(x) = \phi(-x) - 3\int_{0}^{-x/3} h(t')dt' + C\end{equation*}
Then for u to be continuous, $\psi(x)$ must be continuous at 0,
\begin{equation} \psi(0_{+}) = \frac{1}{2}f(0) = \phi(0) + C =\frac{1}{2}f(0)+C=\psi(0_{-})\end{equation}
We get C = 0
Therefore when x< 3t,
\begin{equation} u = \frac{1}{2}[f(x+3t)+f(3t-x)] + \frac{1}{6}[\int_{0}^{x+3t} g(x') dx' + \int_{0}^{3t-x} g(x') dx' ]- 3\int_{0}^{t-x/3} h(t')dt'\end{equation}
Now plug in $f, g, h$, we get
\begin{align}
&u = \cos (x+3t) + 3\cos (x-3t), x>3t\\[2pt]
&u = \cos (x+3t) + 2\cos (3t-x) + 1, 0<x<3t
\end{align}