package ru.parsentev.task_007;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * TODO: comment
 *
 * @author parsentev
 * @since 28.07.2016
 */
public class Expression {
    private static final Logger log = getLogger(Expression.class);

    private String expr;

    public Expression(final String expr) {
        this.expr = expr;
    }

    public double calc() {
        double value = 0;
        double a = Double.parseDouble(String.valueOf(expr.charAt(0)));
        double b = Double.parseDouble(String.valueOf(expr.charAt(2)));
        char c = expr.charAt(1);

        try {
            if (expr.length() > 2) {
                if (c == '+') {
                    value = a + b;
                } else if (c == '-') {
                    value = a - b;
                } else if (c == '*') {
                    value = a * b;
                } else if (c == '/') {
                    value = a / b;
                } else if (c == '^') {
                    value = Math.pow(a, b);
                }
            }
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }

        return value;
    }
}


@@ -456,24 +456,80 @@
  0;%0A        
+for (int i = 0; i %3C expr.length(); i++) %7B%0A            //
 double a = D
@@ -583,24 +583,30 @@
 ));%0A        
+   
+ //
 double b = D
@@ -668,34 +668,208 @@
     
-char c = expr.charAt(1);%0A%0A
+    //expr.indexOf(expr);%0A            char c = expr.charAt(1);%0A            int a = expr.indexOf(i, i + 6);%0A            int b = expr.indexOf(%22%22, a + 1);%0A            int mark = expr.indexOf(i + 7);%0A    
     
@@ -878,16 +878,20 @@
   try %7B%0A
+    
         
@@ -931,24 +931,30 @@
             
+    //
 if (c == '+'
@@ -953,24 +953,62 @@
 c == '+') %7B%0A
+                    if (c == '+')%0A    
             
@@ -1366,26 +1366,16 @@
        %7D
-%0A        %7D
  catch (
@@ -1397,24 +1397,28 @@
 eption e) %7B%0A
+    
             
@@ -1442,26 +1442,39 @@
 ();%0A        
+    %7D%0A        
 %7D
-%0A
 %0A        ret

Update : Дополнительные задачи[#22192]