Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: PEMDAS Calculator

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Question PEMDAS Calculator

    I'm writing a calculator, and to start, I'm writing basic arithmetic functionality. I've figured out how to tackle the "EMDAS" portion of the Order of Ops, however, I don't have a clue on how to simplify parentheses. The code I've written doesn't work in that regard, though everything else so far works great. How would you guys do the parentheses?

    pseudo-code which needs revising/reworking (I've written actual code, but it's fairly confusing...)
     
    solveParentheses(String[] equation):
     
    loop until no more parentheses:
     
    find first parenthesis
    store its location in a variable
     
    find close parenthesis 
    store its location in a variable
     
          If found one but not the other, give error message
     
    save the content of the parentheses into an array
     
    that array = solveParentheses(that array)
     
    simplify order of ops inside parentheses
     
    set the location of end parenthesis to result of simplification
     
    set indices between the first parenthesis and result to "null" 
     
    :end loop
     
    count number of null values
     
    new array of length equation.length-nullcounter
     
    fill array with non-null values
     
    return array
     
    :end function


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: PEMDAS Calculator

    7 + 3 infix
    7 3 + postfix

    The easiest way to evaluate infix equations is to convert them to post fix first.
    Improving the world one idiot at a time!

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: PEMDAS Calculator

    That's not how my algorithm works... Care to elaborate?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: PEMDAS Calculator

    Maybe its not how YOUR algorithm works but I suggested a different algorithm you can use. Have you bothered to Google "infix to postfix"?
    Improving the world one idiot at a time!

  5. #5
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: PEMDAS Calculator

    Yes, I still don't know what it does.

Similar Threads

  1. Help with a calculator
    By minipanda1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 9th, 2013, 10:17 AM
  2. Calculator
    By Andrew Wilson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 08:08 AM
  3. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  4. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 04:27 PM
  5. Calculator help.
    By Skinnyskinny in forum Java Theory & Questions
    Replies: 6
    Last Post: August 1st, 2009, 12:34 PM