Question
Write a complete java program that will implement a calculator. Ask the user to input a string such as 5+3 * 2 and give a
Write a complete java program that will implement a calculator.
Ask the user to input a string such as 5+3 * 2 and give a correct answer of 11
Symbols that the calculator will need to parse and properly implement are:
+ - * / ^ ( ) ^ = exponent
If the user does not enter numbers or the above symbols print out an error as to where the error is.
If the user inputs a wrong equation such as (3*5) + (2 + 3 print out an error that there are missing closing parenthesis.
Equations can be entered as 3+6*(5+2)^2 or 3 + 6* (5 + 2 )^ 2 Notice spaces can be entered at random places.
The easiest way to check for errors and take out spaces is to use regular expressions.
You have to write your own stack classes. Both operator and operand!
You can use linked list as stacks or array. With array, you will have to implement resizing in case the array is too small.
Make sure you check for error and exceptions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started