title: Simplest approach to make a calculator?
body: <p>I've read other questions on this and they're not quite as general as I want this discussion to be. </p>
  
  <p>My question is as stated: What's the simplest approach to making a basic calculator, say with precedence on its operations, and maybe even brackets?</p>
  
  <p>Every time I try to do this, my code gets way more complicated than I usually expect it to. </p>
  
  <p>My usual approach is to take the string input of the calculated request, and then manipulate it. This creates all sorts of problems as I now have to work around the fact that I am using a string rather than some sort of executable Java code.</p>
  
  <p>This is what I generally end up trying to do, regardless of the language I end up using:</p>
  
  <ol>
  <li>Read input string.</li>
  <li>Split the string apart into numbers, brackets, and operators.</li>
  <li>Interpret each string of digits into a number with class integer.</li>
  <li>Create a map from each operation to a method that computes it. Use this to interpret each operator. Then invoke the method on its inputs.</li>
  <li>Create a recursive function with several components. First, the empty string. Second, a single character. Third, a single operation. Fourth, deal with no brackets under precedence. Fifth, go by all set of evaluations in each set of closed set of brackets over and over, recursively calling the function itself whenever necessary, until a single constant is returned.</li>
  </ol>
  
  <p>In addition, for the purpose of Java, how do I invoke a method? Every time I try to do this, I seem to be running into problems. If I want to invoke the addition method <code>add</code> and input numbers <code>2</code> and <code>4</code>, say from another class called <code>Arithmetic</code>, how would I go about this? Mainly, I'm unsure as to what goes into the first input for Java's specific case.</p>
  
  <pre><code>add.invoke(__, {1, 1});
  </code></pre>
  
  <p>I may be calling the <code>invoke</code> method all wrong to begin</p>
  
  <p>To anyone that has tried to build a calculator, has everyone had this much complexity? Is there a simpler way to go about this?</p>
  
  <p>Any discussion here would be great, to be honest.</p>
  
  <p>Edit. I'll clarify how I've defined my <code>add</code> function personally when trying to do this:</p>
  
  <pre><code>public class Arithmetic {
  ...
  
  public static float add(float x, float y) {
      return x+y;
  }
  
  ...
  }
  </code></pre>