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

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

1. ## 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. ## 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.

3. ## 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.