Example $3$ City $A$, City $B$, and City $C$ have 10, 10, and 8 units of a certain machine, respectively. Now it is decided to allocate these machines to City $D$ (18 units) and City $E$ (10 units). It is known that the cost to transport one unit from City $A$ to City $D$ and City $E$ is 200 yuan and 800 yuan, respectively; from City $B$ to City $D$ and City $E$ is 300 yuan and 700 yuan, respectively; from City $C$ to City $D$ and City $E$ is 400 yuan and 500 yuan, respectively.
(1) Suppose $x$ units are transported from City $A$ and City $B$ to City $D$. After all 28 units are transported, find the function of the total cost $w$ (yuan) in terms of $x$ (units), and determine the minimum and maximum values of $w$;
(2) Suppose $x$ units are transported from City $A$ to City $D$, and $y$ units are transported from City $B$ to City $D$. After all 28 units are transported, express the total cost $w$ (yuan) in terms of $x$ and $y$, and determine the minimum and maximum values of $w$.
(1998, National Junior High School Mathematics Competition)
Solution: (1) According to the problem, the number of machines sent from City A, City B, and City C to City D are $x$, $x$, and $18-2x$; the number of machines sent to City E are $10-x$, $10-x$, and $2x-10$. Therefore,
$$
\begin{aligned}
w= & 200 x+300 x+400(18-2 x) \\
& +800(10-x)+700(10-x) \\
& +500(2 x-10) \\
= & -800 x+17200 .
\end{aligned}
$$

Also, $0 \leqslant x \leqslant 10$ and $0 \leqslant 18-2 x \leqslant 8$,
thus $5 \leqslant x \leqslant 9$.
Therefore, $w=-800 x+17200(5 \leqslant x \leqslant 9$ and $x$ is an integer).

This function is a linear function with a negative coefficient for the linear term, so $w$ decreases as $x$ increases.
When $x=9$, the minimum value of $w$ is 10000 yuan; when $x=5$, $w$ reaches its maximum value of 13200 yuan.
(2) According to the problem, the number of machines sent from City A, City B, and City C to City D are $x$, $y$, and $18-x-y$; the number of machines sent to City E are $10-x$, $10-y$, and $x+y-10$. Then
$$
\begin{aligned}
w= & 200 x+800(10-x)+300 y \\
& +700(10-y)+400(18-x-y) \\
& +500(x+y-10) \\
= & -500 x-300 y+17200 .
\end{aligned}
$$

Also, $0 \leqslant x \leqslant 10$, $0 \leqslant y \leqslant 10$, $10 \leqslant x+y \leqslant 18$ (where $x$, $y$ are non-negative integers),
$$
\begin{aligned}
\therefore w & =-200 x-300(x+y)+17200 \\
& \geqslant-200 \times 10-300 \times 180+17200 \\
& =9800 \text{ (yuan). }
\end{aligned}
$$

When $x=10$, $y=8$, $w$ reaches its minimum value of 9800 yuan: $\square$
$$
\begin{aligned}
Also, w & =-200 x-300(x+y)+17200 \\
& \leqslant-200 \times 0-300 \times 10+17200 \\
& =14200 \text{ (yuan). }
\end{aligned}
$$

When $x=0$, $y=10$, $w$ reaches its maximum value of 14200 yuan.