@Override
	public void solve() {
		double A = 0, B = 0, C = 0, D = 0;
		updateRightWeights();
		updateLeftWeights();
		for (Term t : leftTerms) {
			if (t instanceof XTerm) {
				A += ((XTerm) t).coefficient;
			} else if (t instanceof Constant) {
				C += t.weight;
			}
		}

		for (Term t : rightTerms) {
			if (t instanceof XTerm) {
				B += ((XTerm) t).coefficient;
			} else if (t instanceof Constant) {
				D += t.weight;
			}
		}
		try {
			double x = (D - C) / (A - B);
			xVal.setText(x + "");
		} catch (ArithmeticException ae) {

			JOptionPane.showMessageDialog(this, "Sorry! I can't solve that!");
			xVal.setText("0");
		}
		update();
	}