Mathematica version of Example 2.2 in Griffiths.  Notice, that for plotting purposes I don' t worry about hbar and m.  These are set to one.  If you want to really calculate energy level or expectations, you need to be more careful with these constants

Clear[a,A]
f[x_]= A x (a-x)
Integrate[f[x]^2,{x,0,a}]
hbar = 1;
m = 1;
A = Sqrt[30/a^5]
f[x]
ss[x_,n_]= Sqrt[2/a] Sin[n Pi x/a]
energy[n_] = n^2 Pi^2 hbar /(2m a^2)

coef = Table[ Integrate[f[x]  ss[x,i],{x,0,a}],{i,10}]//FullSimplify
a = 1
psi[x_,t_] = Sum[coef[[n]] ss[x,n] Exp[- I  energy[n] t] ,{n,10}]

Animate[Plot[Re[psi[x,t]],{x,0,a},PlotRange->{{0,1},{-2,2}}],{t,0,3,.1}]
Animate[Plot[Abs[psi[x,t]],{x,0,a},PlotRange->{{0,1},{-2,2}}],{t,0,3,.1}]

The first coefficient is by far the largest.  This means that if you were to measure the enrgy, you would most likly get the eigenvalue associated with this stationary state :   energy[1].

N[coef]

Compare this approximation to to the number in example 2.3.  remember we took a = hbar = m = 1.

Sum[Abs[coef[[i]]]^2 energy[i],{i,10}]//N

N[energy[1]]

Sum[Abs[coef[[i]]]^2,{i,10}]//N