To find the number of hats \( x \) that need to be produced and sold to achieve a profit of $8000, we can set up the equation based on the profit function given:
\[ P(x) = 20x - 6000 \]
We want to find \( x \) such that \( P(x) = 8000 \):
\[ 8000 = 20x - 6000 \]
Now, let's solve for \( x \):
- Add 6000 to both sides:
\[ 8000 + 6000 = 20x \] \[ 14000 = 20x \]
- Divide both sides by 20:
\[ x = \frac{14000}{20} \] \[ x = 700 \]
Therefore, producing and selling 700 hats will give a profit of $8000.