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 3 of 3

Thread: So I'm making this program...

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    25
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default So I'm making this program...

    I've been messing around with making an advanced calculator in Java by implementing popular algorithm solving techniques like PEMDAS and SABDM (Both commonly used for Algebra and other equations) and I was wondering, what be the best way to go about doing this?

    Right now, I've implemented PEMDAS, and the first thing it does is search for parenthesis and then cuts what's inside and places them in Arrays. So, you type in:
    (1+1)
    and it cuts out and prints:
    1+1
    So, then it has to calculate it, but I don't know where to start. I can't just be like you know:
    a = bgc
    Where a is the answer, b is the first number, g is the solving type, and c is the other number.
    So what should I do?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: So I'm making this program...

    When attempting this sort of program it generally helps if you convert the infix expression (1 + 2) to a postfix expression (1 2 +). If you do this correctly then you can incorporate brackets as well. Then to evaluate the postfix expression it is achieved by using a Stack. When you get to an operand push it onto the Stack. When you get to an operator you pop 2 values of the Stack, apply the operator and push the result back onto the Stack. At the end the only value left on the Stack will be the final result.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    25
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: So I'm making this program...

    I like your ideas, but do you think the postfix expression would be more of a hassle than anything?

    Anyway, I finished the bracket cutting, it cuts out pieces in brackets and puts them in a List called "Parts"
    I just gotta make Java cut the brackets from the main equation and replace them with the answers to the bracketed problems possibly, then turn that final equation string into an expression that can be calculated like I will with that actual bracketed strings.

Similar Threads

  1. Making Methods
    By kilroyjr in forum Java Theory & Questions
    Replies: 7
    Last Post: April 7th, 2011, 06:19 PM
  2. Very basic program but its making me crazy
    By craig carl in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 2nd, 2011, 03:16 PM
  3. Making a clock
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 7th, 2011, 04:36 PM
  4. Need help making program
    By ixjaybeexi in forum Collections and Generics
    Replies: 5
    Last Post: December 6th, 2009, 11:36 PM
  5. Digital map application with Java GUI
    By donjuan in forum AWT / Java Swing
    Replies: 3
    Last Post: May 15th, 2009, 04:32 AM