Fix any open, bounded set $U \subset \mathbb{R}^n$ and suppose that $u \in C^2(U) \cap C(\bar{U})$ is a solution of $$-\Delta u = f \,\,\,\text{in}\,U$$ $$u=g \,\,\,\,\,\,\text{on}\,\,\,\partial U,$$ where $f \in C(\bar{U}), g\in C(\partial U).$ Prove that $$\sup_{x \in U}|u(x)| \leq C\left(\sup_{y \in \partial U}|g|+\sup_{x \in U}|f(x)|\right),$$ for constant C depending only on $n$ and $\sup_{x,y\in U}|x-y|.$
Proof:
Based on the hint, I showed that the function $v(x)=u(x)+\dfrac{|x|^2}{2n}\sup_{y \in U}|f(y)|$ is subharmonic. Then applying the weak maximum principle, we get \begin{align*} \sup_{x \in U} |v(x)| \leq \sup_{x \in \partial U} |u(x)|+ \dfrac{1}{2n}\sup_{x \in \partial U} |x|^2.\sup_{y\in U}|f(y)| \end{align*}
I don't know how to end up with the final inequality. Furthermore, I think we have the constant $C$ will depend on $n$ and $sup_{x \in \partial U} |x|^2$, how it could be depend on $\sup_{x,y\in U}|x-y|?$
Could you please give me some ideas?
You are very close. Since $v$ is subharmonic, from the maximum principle you have that $$ u(x)+ \frac 1{2n} \vert x\vert^2\sup_{\Omega}\vert f\vert =v\leq\sup_\Omega v = \sup_{\partial \Omega} v \leq \sup_{\partial \Omega}\vert u \vert + \frac 1{2n} \big ( \sup_{x\in \Omega} \vert x\vert\big )^2\sup_{\Omega}\vert f\vert \qquad \text{for all } x\in \Omega.$$ Since $u=g$ on $\partial \Omega$, this gives $$u(x) \leq \sup_{\partial \Omega}\vert g \vert + \frac 1{2n} \big ( \sup_{x\in \Omega} \vert x\vert\big )^2\sup_{\Omega}\vert f\vert-\frac 1{2n} \vert x\vert^2\sup_{\Omega}\vert f\vert \leq \sup_{\partial \Omega}\vert g \vert + \frac 1{n} \big ( \sup_{x\in \Omega} \vert x\vert\big )^2\sup_{\Omega}\vert f\vert. \tag{$\ast$} $$ This implies that $$ \sup_\Omega u \leq C \big ( \sup_{\partial \Omega}\vert g \vert + \sup_{\Omega}\vert f\vert\big ) $$ with $$C=\frac 1{n} \big ( \sup_{x\in \Omega} \vert x\vert\big )^2+1. $$ Applying ($\ast$) to $-u$ further implies that $$ \sup_\Omega \vert u\vert \leq C \big ( \sup_{\partial \Omega}\vert g \vert + \sup_{\Omega}\vert f\vert\big )$$ with $C$ as before.
Now this is almost what you want: the only issue is that you want $C$ to depend on $\operatorname{diam}\Omega := \sup_{x,y\in \Omega}\vert x-y\vert$ instead of $\sup_{x\in \Omega } \vert x \vert $ as we obtained above. To do this, try replacing the $\vert x \vert^2$ in your guess with $\vert x- a\vert^2$ where $a\in \Omega$ is arbitrary. Then repeat the arguments exactly as above, using that $$\sup_{x\in \Omega } \vert x -a\vert \leq \operatorname{diam} \Omega $$ to obtain the desired inequality with $$C=\frac 1 n (\operatorname{diam} \Omega)^2 +1 .$$