The strategy is to write every element as a power of the generator of $G/Z(G)$ times a central element, then use the fact that central elements commute with everything.
**Step 1: Express arbitrary elements.**
Let $Z = Z(G)$ and suppose $G/Z = \langle yZ \rangle$ for some $y \in G$. For any $g \in G$, the coset $gZ$ is a power of $yZ$, say $gZ = (yZ)^i = y^i Z$. So $g = y^i z_1$ for some $z_1 \in Z$.
Similarly, for any $h \in G$, $h = y^j z_2$ for some $j \in \mathbb{Z}$ and $z_2 \in Z$.
**Step 2: Compute the product in both orders.**
Since $z_1, z_2 \in Z(G)$, they commute with every element of $G$. Therefore:
\begin{align*}
gh &= y^i z_1 \cdot y^j z_2 = y^i y^j z_1 z_2 = y^{i+j} z_1 z_2, \\
hg &= y^j z_2 \cdot y^i z_1 = y^j y^i z_2 z_1 = y^{i+j} z_1 z_2.
\end{align*}
So $gh = hg$ for all $g, h \in G$, and $G$ is abelian.