4 Replies Latest reply: Dec 22, 2007 8:45 AM by 807601 RSS

    Char arrays is it the right soultion for this problem

    807601
      I've got enumerated types with each enum constant a different behavior for some method. (+, - , /, *)

      I take a string i.e "(5 + 4) * (4 - 2)"
      and place each string char into this array

      String expression = "(5 + 4) * (4 - 2)" ;
      char[] c = express.toCharArray();

      I've been trying figure out how inow apply my enums method to the char array. Taking boldBODMAS*bold* in account.

      enum Operation {
      PLUS { double eval(double x, double y) { return x + y; } }
      .....

      What fristly was spliting the string at brackets
      String[] temp = express.split("[()]");
      This trunt out not to work weel for nested mathematical
      expressions ie. (4 + (2 * (2 - 1))) * 1.2

      I'm quite new to java programming, any ideas/direction on what i should do would be great guys, thanks.