Trick for a definite integral 
Solve $$I=\displaystyle\int_0^{\pi}x^2(\pi-x)\sin(n\pi x)\, dx$$

How can solve for this case? Integration by parts? I think that I can do this:
$$u=x^2(\pi-x),\quad dv=\sin(n\pi x)\, dx$$
Does it work?
 A: Yes, your approach works.
Let's go along with your idea and use
$$u=x^2(\pi-x)=\pi x^2-x^3,\quad\mathrm{d}u=(2\pi x-3x^2)\mathrm{d}x=x(2\pi-3x)\mathrm{d}x$$
$$\mathrm{d}v=\sin(n\pi x)\mathrm{d}x,\quad v=-\frac{1}{n\pi}\cos(n\pi x)$$
You then have
$$\left[-\frac{\pi x^2-x^3}{n\pi}\cos(n\pi x)\right]_0^{\pi}+\int_0^{\pi}x(2\pi-3x)\frac{1}{n\pi}\cos(n\pi x)\mathrm{d}x$$
What you've done is reduced the highest power of $x$, while still having the integral of $f(x)$ times some trigonometric function. All you have to do is repeat this process until you're left with the integral of either just $\sin(n\pi x)$ or $\cos(n\pi x)$.
Can you go on from here?
You can use this trick for any integral of the form
$$A\int x^nf(x)\mathrm{d}x$$
where $A$ is a constant, $n$ is a whole number and $f(x)=\sin(ax)$ or $f(x)=\cos(ax)$. On a side note, it also works for cases where $f(x)=e^{ax}$.
A: $$\int_0^{\pi}x^2(\pi-x)\sin(n\pi x)\, dx\\
=x^2(x-\pi)\frac{\cos(n\pi x)}{n\pi}\Bigg|_0^\pi+
\int_0^{\pi}(2x\pi-3x^2)\frac{\cos(n\pi x)}{n\pi}\, dx\\=
\int_0^{\pi}x(2\pi-3x)\cos(n\pi x)\, dx\\=
x(2\pi-3x)\frac{\sin(n\pi x)}{n^2\pi^2}\Bigg|_0^\pi - \int_0^{\pi}(2\pi-6x)\frac{\sin(n\pi x)}{n^2\pi^2}\, dx\\=
-\frac{\sin(n\pi^2)}{n^2} - \int_0^{\pi}(2\pi-6x)\frac{\sin(n\pi x)}{n^2\pi^2}\, dx
\\=
-\frac{\sin(n\pi^2)}{n^2} +
(2\pi-6x)\frac{\cos(n\pi x)}{n^3\pi^3}\Bigg|_0^\pi- 
\int_0^{\pi}(-6)\frac{\cos(n\pi x)}{n^3\pi^3}\, dx\\=
-\frac{\sin(n\pi^2)}{n^2} -
\frac{4\cos(n\pi^2)-2}{n^3\pi^2}
+6
\int_0^{\pi}\frac{\cos(n\pi x)}{n^3\pi^3}\, dx
\\=
-\frac{\sin(n\pi^2)}{n^2} -
\frac{4\cos(n\pi^2)-2}{n^3\pi^2}
+6
\frac{\sin(n\pi x)}{n^4\pi^4}\Bigg|_0^\pi\\=
-\frac{\sin(n\pi^2)}{n^2} -
\frac{4\cos(n\pi^2)-2}{n^3\pi^2}
+6
\frac{\sin(n\pi ^2)}{n^4\pi^4}$$
