public double solve() {
        JEP solver = new JEP();
        double size = (upper - lower) / count;
        
        double running = 0;

        solver.addStandardConstants();
        solver.addStandardFunctions();

        solver.addVariable("x", 0);
        solver.parseExpression(expression);
        
        for (int i = 0; i < count; i++) {
            switch (method) {
            case MIDDLE:
                solver.addVariable("x", lower + size * (i + 0.5));
                break;
            case RIGHT:
                solver.addVariable("x", lower + size * (i + 1));
                break;
            case LEFT:
                solver.addVariable("x", lower + size * i);
                break;
            case TRAPAZOID:
                solver.addVariable("x", lower + size * i);
                break;
            }
            
            if (method == SolveMethod.TRAPAZOID) {
                running += solver.getValue() * (i == 0 ? 1 : 2) * size;
                if (i == count - 1) {
                    solver.addVariable("x", lower + size * (i + 1));
                    running += solver.getValue() * size;
                }
            } else {
                running += solver.getValue() * size;
            }
        }
        
        return running * (method == SolveMethod.TRAPAZOID ? 0.5 : 1);
    }